[R] paste0 in file path

Leslie Rutkowski leslie.rutkowski at gmail.com
Wed Aug 31 17:50:07 CEST 2016


Hi,

I'm trying to reshape and output 8 simple tables into excel files. This is
the code I'm using

  for (i in 1:8) {
  count <- table(mydata$ctry, mydata[,paste0("q0",i,"r")])
  dat <- as.data.frame(q01count)

  wide <- reshape(dat,
                  timevar="Var2",
                  idvar="Var1",
                  direction="wide")
   write.xlsx(wide, file=paste0(i, 'C:/temp/q0',i,'r.xlsx'))
  }

All goes well until the write.xlsx, which produces the error

Error in .jnew("java/io/FileOutputStream", jFile) :
  java.io.FileNotFoundException: 1C:\temp\q01r.xlsx (The filename,
directory name, or volume label syntax is incorrect)

Among other things, I'm puzzled about why a "1" is getting tacked on to the
file path.

Any hints?

Thanks,
Leslie

	[[alternative HTML version deleted]]



More information about the R-help mailing list