0

First let me apologize for using Excel terms for Google Sheets. I want to grab data from a single sheet in a workbook, do something, then write a new sheet in the same workbook. For example;

library(googlesheets4)

pot <- read_sheet("https://docs.google.com/spreadsheets/d/1tw0tK0RQf1F4WXA5eo24wDjOR0jrqoRp91SI4x7YnqU/edit#gid=0")

pot.sum<-pot%>%
  group_by(Treat) %>%
  summarise(Mean = mean(Value))

Now I want want to write pot.sum to a new spreadsheet in the same workbook. I know the functions gs4_create() and write_sheet(), but I am missing how to direct where the new sheet is written. Thank you for any help you could provide.

Dustin
  • 183
  • 7

1 Answers1

2

The following will help you do it:

# Load packages

library(googlesheets4)

library(tidyverse)

link <- "https://docs.google.com/spreadsheets/d/1tw0tK0RQf1F4WXA5eo24wDjOR0jrqoRp91SI4x7YnqU"

pot <- read_sheet(link)

pot.sum <- pot %>%
  group_by(Treat) %>%
  summarise(Mean = mean(Value))


pot.sum %>% write_sheet(ss = link, sheet = "pot.sum")

Then you can check the sheet in the main Google Sheets, https://docs.google.com/spreadsheets/d/1tw0tK0RQf1F4WXA5eo24wDjOR0jrqoRp91SI4x7YnqU

gbganalyst
  • 364
  • 4
  • 8
  • Thank you @gbganalyst. I get the following error, "Error: Don't know how to make an instance of from something of class ." Any ideas? – Dustin Aug 15 '22 at 23:02
  • You are welcome, @Dustin. I made a mistake in my code. It has now been updated. – gbganalyst Aug 17 '22 at 08:42