write_cvs() not working... ?

Hi,
I'm trying to save a tibble to as a csv file to but I nothing happens when I run the code.
I thought of choosing the directory by pointing to a project to get the file path.
No errors, but no file as well on the directory.
Checked libraries and all are updated and loaded.

(a <- tibble(
  "x" = sample(100,100),
  "y" = sample(150,100),
  "z" = sample(275,100)
))

path_a <- file.path(choose.files())
path_a
#>[1] "C:\\Users\\myname\\Dropbox\\r4ds.Rproj"
write_csv(a, path = path_a, append = FALSE, col_names = TRUE)
````

Could you use a text editor to look at the contents of this file ?

C:\\Users\\myname\\Dropbox\\r4ds.Rproj

I tried this on my own machine, and even the the icon still looks like a .Rproj icon, the contents are in fact the table I wrote with write_csv().

Thanks for the reply.

You are correct, opening with a text editor the data is as csv.

How would go about doing it and naming the file? I probably shouldn't use the full file path because it has the name and file type. lol what a mess I made...

If you look in the RStudio pane that says 'Console' in the upper left, you should also see a path -- that's where RStudio will automatically save your file unless you give write_csv() a full file path, or path relative to the Console path.

So if you want to save the file in the directory specified by the Console path you could run

write(a, 'my_file.csv')

You could use any string for the file name, but it's conventional to at least use a '.csv' suffix in this case. Does that help?

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.