nbaes
June 9, 2022, 1:23am
1
For example, if I want to save the .csv file below in a folder called "output" , is there an argument I am missing from the documentation of this function OR better function to use? write.csv function - RDocumentation
write.csv(data, file='data.csv')
Just pass the desired file path to the file
argument.
write.csv(data, file='output/data.csv')
2 Likes
I like to use file.path() as it means I don't have to remember which way the slashes go...
write.csv(data, file=file.path('output','data.csv'))
1 Like
nbaes
June 15, 2022, 1:51pm
4
Thanks! what if the folder (output) is inside another folder (data) inside the working directory?
nbaes
June 15, 2022, 1:51pm
5
Thanks! Do you know the equivalent for if the folder (output) is inside another folder (data) inside the working directory?
Is this what you mean?
write.csv(data, file='data/output/data.csv')
1 Like
nbaes
June 15, 2022, 2:11pm
7
Yes! This format also worked for the here function--thank you very much.
xx_path <- here("data/input","xx_count_relfreq.csv")
Just for you to be aware, this is not specific to R or coding, it seems you are having problems understanding how to define a file path, this is a general computing concept.
A path (or filepath, file path, pathname, or similar) is a string of characters used to uniquely identify a location in a directory structure. It is composed by following the directory tree hierarchy in which components, separated by a delimiting character, represent each directory. The delimiting character is most commonly the slash ("/"), the backslash character ("\"), or colon (":"), though some operating systems may use a different delimiter. Paths are used extensively in computer science to...
nbaes
June 15, 2022, 2:24pm
9
That makes sense--thanks. Learnt R for statistics, and no background in computing so this is helpful. Please feel free to link any other resources.
system
Closed
June 23, 2022, 5:41am
11
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.