I am writing a csv file to a folder using write.table()
function. After opening the file, when I try again to write the file to the folder it gives me this error.
Error in file(file, ifelse(append, "a", "w")) :
cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
cannot open file 'D:/My_Work/output/Mydata.csv': Permission denied
I understood that this error comes because the file is already opened. Once I close the file and try writing to the folder, it works fine. I wanted to know if there is any way that I could write the file to the folder even when the file is already open and want to update the opened file with whatever changes made to the new file.
Below is the code: I am reading a sheet from an Excel workbook and saving it as a separate CSV file to a folder, file type as Microsoft Excel Comma Separated Values File.
config_file = loadWorkbook("D:/My_Work/Input/Main.xls")
where_tab = readWorksheet(config_file, sheet = "where", header = TRUE)
write.table(where_tab,"D:/My_Work/output/Mydata.csv",sep = ",",col.names = NA)
Using this package:
if(!require(XLConnect)){
install.packages("XLConnect")
}
library(XLConnect)