On 21/03/2016 7:53 AM, Sunny Singha 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)


The <U+1ED9> and similar strings represent Unicode characters. I would guess that they are being translated to the <U+1ED9> format before being used as a filename, and the < and > symbols are not allowed in filenames in Windows.

This is a limitation of the way R handles non-ASCII characters in Windows, and there's not much you can do about it other than avoiding characters which do not display in Latin1 (or whatever R sees as your native character set).

Duncan Murdoch

______________________________________________
R-help@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.

Reply via email to