[R] Please guide -- Error during export in csv format
Ben Tupper
btupper at bigelow.org
Mon Mar 21 13:05:52 CET 2016
Hi,
You are defeating the purpose of the file.path() function by providing a path separator in the first argument; you used './', but try instead...
my.file1 <- file.path('.', paste0('likes','_',name,'_',grp_id,'.csv'))
Also, there appear to be spaces in the 'name' argument - that might be causing you an issue but it is hard to know. You might try wrapping the value of my.file1 in quotes using shQuote() or maybe even dQuote() - I'm not sure as I am not on Windows.
Cheers,
Ben
> On Mar 21, 2016, at 7:53 AM, Sunny Singha <sunnysingha.analytics at gmail.com> wrote:
>
> Please guide,
> I'm exporting data in '.csv' format in the Windows user directory, I
> have full access to. The write operation happens within a for loop.
>
> Each iteration exports data in csv format in the user directory. The
> issue is that the data gets exported for all the 9 iterations but
> fails for 10th iteration giving below error message.
>
> 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 './/posts_H<U+1ED9>i nh<U+1EEF>ng ngu<U+1EDD>i
> d<U+1ED3>ng hành cùng line_752518568125567.csv': Invalid argument
> Called from: file(file, ifelse(append, "a", "w"))
>
> The export directory path is current directory with 'name' extracted as below:
> my.file1: .//likes_H<U+1ED9>i nh<U+1EEF>ng ngu<U+1EDD>i d<U+1ED3>ng
> hành cùng line_752518568125567.csv
> my.file2: .//posts_H<U+1ED9>i nh<U+1EEF>ng ngu<U+1EDD>i d<U+1ED3>ng
> hành cùng line_752518568125567.csv
>
> I wondering if the error is due to the the complicated filename ?
> Below is the line of code I have used within loop to export data.
>
> my.file1 <- file.path('./', paste0('likes','_',name,'_',grp_id,'.csv'))
> my.file2 <- file.path('./', paste0('posts','_',name,'_',grp_id,'.csv'))
>
> write.csv(posts_frame, file=my.file2, row.names = F)
> write.csv(likes_frame, file = my.file1, row.names = F)
>
> Regards,
> Sunny
>
> ______________________________________________
> 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.
Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org
More information about the R-help
mailing list