Диана
Диана

Reputation: 113

Save r dataframe to google sheets

I have performed some calculations and created some data in r, it is saved to csv, but now I want to save the same dataframes (mydata) to Google Sheets.

ver. 1 : I would like to save them in google sheets format to the folder on a desctop. Is this possible?

ver2. Save directly to the Google drive. How I can here point the folder where to save the files?

I have uploaded: library(googlesheets4) library(googledrive) Created the connection to drive gs4_auth()

and then I was trying to use a) Sheet1 <- sheet_write(mydata) # # this gave me a strange blank google sheet with strange name on google drive

b) I have thried to use drive_mv("Sheet1", path = "/Users/user/Desktop/Data") and also it returned me mistake.

Now I am totally lost, and wonder what should i do to save existing dataframe to Google Sheet? How I can indicate location where to save?

Upvotes: 4

Views: 2070

Answers (1)

Isaac
Isaac

Reputation: 986

If you want to upload a dataframe into google sheets, first you need to create the spreadsheets in google drive. Then, you need to copy the link of that sheet into the function gs4_get. Maybe is not the best approach, but for me works.

library(googlesheets4)

mydata %>%
  write_sheet(
    ss = gs4_get(
      "https://docs.google.com/spreadsheets/...." # Replace the access link to the spreadsheets
    ),
    sheet = "Name_your_sheet"
  )

Upvotes: 2

Related Questions