'How to abbreviate and use repetitive expressions in R
I'm making a code that converts data and labels of SAV file into one XLSX file. In the code, same paths and file names are repeatedly used within functions, so is there a way to define and abbreviate them?
library(foreign)
library(xlsx)
data <- read.spss('path/file_name.SAV', use.value.labels=FALSE, to.data.frame=TRUE)
label <- read.spss('path/file_name.SAV', use.value.labels=TRUE, to.data.frame=TRUE)
write.xlsx(data, 'path/file_name.xlsx', sheetName="DATA", col.names=TRUE, row.names=FALSE, append=FALSE, showNA=FALSE)
write.xlsx(label, 'path/file_name.xlsx', sheetName="LABEL", col.names=TRUE, row.names=FALSE, append=TRUE, showNA=FALSE)
Solution 1:[1]
Have you tried using variables for path/file names e.g.?
fn <- "file_name.SAV"
dr <- "/directory/here/"
full_path <- paste0(dr, fn)
data <- read.spss(full_path)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Xlrv |
