Replace sheet using googlesheets in R

I have 2 questions.

  • How to overwrite a worksheet in an existing spreadsheet using the googlesheets package in R?

  • How do I create a new worksheet in an existing spreadsheet using the googlesheets package in R?

I couldn't find anything in the documentation.

+3


source to share


1 answer


To add a new worksheet to an existing table:

require(googlesheets)
#first get the existing spreadsheet
existing_spreadsheet <- gs_title("title")  
#Then add the new worksheet to the existing sheet 
gs_ws_new(existing_spreadsheet
       , ws_title = "worksheet title"  #make sure it doesn't exist already
       , input = your_input #data.frame or data.table
       , trim = TRUE  #optional if you want your worksheet trimed
              )

      



I have not been able to find a direct way to overwrite sheets in an existing spreadsheet. So I had to delete the existing worksheet and add it again as a new worksheet.

#first delete the existing worksheet
existing_spreadsheet <- gs_ws_delete(existing_spreadsheet, "work sheet title you want updated")
# Then add the newworksheet with new data
gs_ws_new(existing_spreadsheet
        , ws_title = "worksheet title" 
        , input = your_new_data #data.frame or data.table
        , trim = TRUE  #optional if you want your worksheet trimed
      )

      

0


source







All Articles