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
paste0 in file path
4 messages · Leslie Rutkowski, Uwe Ligges, Bob Rudis +1 more
On 31.08.2016 17:50, Leslie Rutkowski wrote:
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'))
^^ remove the i? Best, Uwe Ligges
}
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]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
if the files are supposed to be "1r.xlsx", "2r.xlsx" (etc) then you need to ensure there's a "/" before it. It's better to use `file.path()` to, well, build file paths since it will help account for differences between directory separators on the various operating systems out there. On Wed, Aug 31, 2016 at 11:54 AM, Uwe Ligges <
ligges at statistik.tu-dortmund.de> wrote:
On 31.08.2016 17:50, Leslie Rutkowski wrote:
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'))
^^
remove the i?
Best,
Uwe Ligges
}
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]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posti ng-guide.html and provide commented, minimal, self-contained, reproducible code.
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posti ng-guide.html and provide commented, minimal, self-contained, reproducible code.
Also, the recommended way to build file paths is to use file.path(), i.e.
file.path("C:", "temp", filename)
rather than
paste0("C:/temp/", filename)
BTW, R provides tempdir() that gives you the temporary directory that
R prefers to use on your OS. So, you might want to consider using:
paste0(tempdir(), filename)
It is specific and temporary to the R session running though, so if
you want to store things across R sessions, tempdir() is not what you
want to use.
/Henrik
On Wed, Aug 31, 2016 at 8:54 AM, Uwe Ligges
<ligges at statistik.tu-dortmund.de> wrote:
On 31.08.2016 17:50, Leslie Rutkowski wrote:
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'))
^^
remove the i?
Best,
Uwe Ligges
}
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]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.