Write data.frame to Google Sheet and place in a specific Google Drive folder?

I just used gs_new() from the googlesheets package to write a data.frame to a Google Sheet. That's a really neat tool. Today was one of my first actual chances to use it.

My question: is there a way to create the new sheet in a specific Google Drive folder? I wanted to place the Sheet inside an existing, shared folder.

Looking at the function arguments to gs_new(), I didn't see a way to do this. So I used the drive_mv() function from the googledrive package to move it. This two-step process is very workable and handy. I was just wondering if it could be done in one.

Thanks in advance!

Yep, check out the googledrive package:

1 Like

Yes, it looks like drive_mkdir() is what the user is asking for:
https://www.rdocumentation.org/packages/googledrive/versions/0.1.3/topics/drive_mkdir

1 Like

Thank you for the quick replies. I appreciate it.

And yep, I did use googledrive after creating the new sheet with googlesheets. To be more explicit, this is what my code looks like using the iris dataset and a folder in "My Drive" called "R/Demo":

library(googlesheets)
library(googledrive)

gs_auth()

data(iris)

gs_new(title = "iris sheet", input = iris)

drive_mv("iris sheet", path = "~/R/Demo/")

So, the two-steps aren't too tough. I was just curious to know if it could be done just using googlesheets alone.

I can also see how it's possible to use only the googledrive package by saving the data.frame as a .csv and using drive_upload(). I prefer to skip the csv step, however.

And @olyerickson, I didn't think I needed drive_mkdir() because the folder already existed. Are you saying there's way to use that function and gs_new() together?

Lastly, it could have been my error but I didn't see a way to tag this question with "googledrive". Only "googlesheets" was available.

Thanks again.

This topic was automatically closed 21 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.