10

I have a problem with the write.xlsx2 function of xlsx R package. For instance, see the code below.

main_path<-"~/mydir/"
read.xlsx2(paste0(main_path,"my_input_excel.xlsx"), sheetIndex=1)
a<-1
write.xlsx2(a, paste0(main_path,"my_output_excel.xlsx"), sheetName="Sheet1", col.names=TRUE, row.names=FALSE, append=FALSE)

While read.xlsx2 function works fine, write.xlsx2 function gives the error

Error in .jnew("java/io/FileOutputStream", jFile) :
java.io.FileNotFoundException: /mydir/my_output_excel.xlsx (No such file or directory)

When I remove the paste0 part and write only the file name everything is fine again. So the problem is to define path.

p.s I am wondering, perhaps the write.xlsx ignores the tilde ~ so path definition becomes garbage.

4

1 回答 1

8

将“~/”替换为“Users//”适用于 Mac(可能也适用于 Linux)。尽管如此,我仍然无法理解如何read.xlsx以及write.xlsx可能以如此根本的方式有所不同。

于 2015-06-11T16:41:38.207 回答