在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):tidyverse/googlesheets4开源软件地址(OpenSource Url):https://github.com/tidyverse/googlesheets4开源编程语言(OpenSource Language):R 100.0%开源软件介绍(OpenSource Introduction):googlesheets4Overviewgooglesheets4 provides an R interface to Google Sheets via the Sheets API v4. It is a reboot of an earlier package called googlesheets. Why 4? Why googlesheets4? Did I miss googlesheets1 through 3? No. The idea is to name the package after the corresponding version of the Sheets API. In hindsight, the original googlesheets should have been googlesheets3. InstallationYou can install the released version of googlesheets4 from CRAN with: install.packages("googlesheets4") And the development version from GitHub with: # install.packages("devtools")
devtools::install_github("tidyverse/googlesheets4") CheatsheetYou can see how to read data with googlesheets4 in the data import cheatsheet, which also covers similar functionality in the related packages readr and readxl. Authgooglesheets4 will, by default, help you interact with Sheets as an
authenticated Google user. If you don’t plan to write Sheets or to read
private Sheets, use For this overview, we’ve logged into Google as a specific user in a hidden chunk. Attach googlesheets4library(googlesheets4) ReadThe main “read” function of the googlesheets4 package goes by two names, because we want it to make sense in two contexts:
googlesheets4 is pipe-friendly (and
reexports Read from
These all achieve the same thing: # URL
read_sheet("https://docs.google.com/spreadsheets/d/1U6Cf_qEOhiR9AZqTqS3mbMF3zt2db48ZP5v3rkrAEJY/edit#gid=780868077")
#> ✓ Reading from "gapminder".
#> ✓ Range 'Africa'.
#> # A tibble: 624 × 6
#> country continent year lifeExp pop gdpPercap
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 Algeria Africa 1952 43.1 9279525 2449.
#> 2 Algeria Africa 1957 45.7 10270856 3014.
#> 3 Algeria Africa 1962 48.3 11000948 2551.
#> 4 Algeria Africa 1967 51.4 12760499 3247.
#> 5 Algeria Africa 1972 54.5 14760787 4183.
#> # … with 619 more rows
# Sheet ID
read_sheet("1U6Cf_qEOhiR9AZqTqS3mbMF3zt2db48ZP5v3rkrAEJY")
#> ✓ Reading from "gapminder".
#> ✓ Range 'Africa'.
#> # A tibble: 624 × 6
#> country continent year lifeExp pop gdpPercap
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 Algeria Africa 1952 43.1 9279525 2449.
#> 2 Algeria Africa 1957 45.7 10270856 3014.
#> 3 Algeria Africa 1962 48.3 11000948 2551.
#> 4 Algeria Africa 1967 51.4 12760499 3247.
#> 5 Algeria Africa 1972 54.5 14760787 4183.
#> # … with 619 more rows
# a googledrive "dribble"
googledrive::drive_get("gapminder") %>%
read_sheet()
#> ✓ The input `path` resolved to exactly 1 file.
#> ✓ Reading from "gapminder".
#> ✓ Range 'Africa'.
#> # A tibble: 624 × 6
#> country continent year lifeExp pop gdpPercap
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 Algeria Africa 1952 43.1 9279525 2449.
#> 2 Algeria Africa 1957 45.7 10270856 3014.
#> 3 Algeria Africa 1962 48.3 11000948 2551.
#> 4 Algeria Africa 1967 51.4 12760499 3247.
#> 5 Algeria Africa 1972 54.5 14760787 4183.
#> # … with 619 more rows Note: the only reason we can read a sheet named “gapminder” (the last example) is because the account we’re logged in as has a Sheet named “gapminder”. See the article Find and Identify Sheets for more about specifying the Sheet you want to address. See the article Read Sheets for more about reading from specific sheets or ranges, setting column type, and getting low-level cell data. Write
(ss <- gs4_create("fluffy-bunny", sheets = list(flowers = head(iris))))
#> ✓ Creating new Sheet: "fluffy-bunny".
#> Spreadsheet name: fluffy-bunny
#> ID: 1NEnHGqHVlNJZvDQp9uk8vrCLhoXNBl8qLjm3loZf5cU
#> Locale: en_US
#> Time zone: Etc/GMT
#> # of sheets: 1
#>
#> (Sheet name): (Nominal extent in rows x columns)
#> flowers: 7 x 5
head(mtcars) %>%
sheet_write(ss, sheet = "autos")
#> ✓ Writing to "fluffy-bunny".
#> ✓ Writing to sheet 'autos'.
ss
#> Spreadsheet name: fluffy-bunny
#> ID: 1NEnHGqHVlNJZvDQp9uk8vrCLhoXNBl8qLjm3loZf5cU
#> Locale: en_US
#> Time zone: Etc/GMT
#> # of sheets: 2
#>
#> (Sheet name): (Nominal extent in rows x columns)
#> flowers: 7 x 5
#> autos: 7 x 11
Where to learn moreGet started is a more extensive general introduction to googlesheets4. Browse the articles index to find articles that cover various topics in more depth. See the function index for an organized, exhaustive listing. ContributingIf you’d like to contribute to the development of googlesheets4, please read these guidelines. Please note that the googlesheets4 project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms. PrivacyContextgooglesheets4 draws on and complements / emulates other packages in the tidyverse:
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论