4

This seems like a very simple question, but I can't find the answer elsewhere, so I am hoping someone here can point me in the right direction. I am writing CSVs with an R script, and have reached the following 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 'Package2011logs.csv': Invalid argument

This error is the result of the code:

x = paste(paste(ty,yr, sep=""), "logs.csv", sep="")
write.csv(logscuml, file = x, row.names = FALSE)

Where logscuml is a dataframe with 28 observations of 103 variables, ty = "Package", and yr = "2011". This particular block of code occurs within a for loop within another for loop, if that is important.

My working directory is set up correctly, and

list.files(getwd())

returns the appropriate filelist. None of the CSVs I am attempting to work with are open on my OS, so I'm not sure what the problem is. No errors are brought up when using read.csv() to open different files for reading from the same wd earlier in the R script. To make this weirder, this code seemed to work fine multiple times before. Is it because I'm writing to an onlinedrive? Can anyone help with this?

7
  • What exactly is an "onlinedrive"? Can you save other files to that directory? What OS are you using? Commented Jul 3, 2015 at 17:45
  • Windows 8, reading and writing from files to a folder on a Microsoft OneDrive. Commented Jul 3, 2015 at 18:15
  • completely unrelated: paste0(x) is the same as paste(x,sep="") and is more parsimonious ;-) Commented Jul 3, 2015 at 18:16
  • try evaluating file("Package2011logs.csv","w") by itself; same error? Will probably have to follow up with close("Package2011logs.csv") btw. Commented Jul 3, 2015 at 18:22
  • thanks for paste() tip! evaluating files by file("Package2011logs.csv","w") produces identical error, unfortunately. Commented Jul 3, 2015 at 18:26

1 Answer 1

8

For anyone who cares about the answer, this error is the result of certain files being in "Online only" mode. A manual, non-automatic sync of the shared drive forced these problem files into being "Available offline" and eliminated the error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.