My R file contains one data frame. The data frame has 12838 rows and 51 columns.
I am attempting to write each row in one of the columns to separate .txt files.
In addition, I am attempting to name each file using another column from the data frame.
The code I am using right now only produces 587 txt files (with the right name), until I receive two errors.
I am trying:
for (i in 1:nrow(r_Data)) {
content <- as.character(r_Data$fulltext[i])
filename <- as.character(r_Data$`Style of Cause`[i])
write(content, file = paste0(filename, ".txt"))
}
I get two errors:
First error:
Error in file(file, ifelse(append, "a", "w")) : cannot open the connection
Second error:
In addition: Warning message: In file(file, ifelse(append, "a", "w")) : cannot open file 'City of Toronto Economic Development Corporation v. Information and Privacy Commissioner/ Ontario.txt': No such file or directory
More Context:
I do not understand these errors. Especially the second one, as it is the 12,205th row in my data frame ... yet I the code is only outputting 587 rows.
Further, the error seems to be indicating the file/directory is not there ... but the code is able to access 587 rows already ...
Any help would be greatly appreciated.
P.S. If my Stack OverFlow question asking etiquette/syntax is wrong, I kindly ask you to correct me rather than down voting my question, and I will implement the corrections!