【问题标题】:How to use require(googlesheets) properly?如何正确使用 require(googlesheets)?
【发布时间】:2015-07-06 02:50:11
【问题描述】:

我最近通过

下载了googlesheets
devtools::install_github("jennybc/googlesheets")

并遇到一些困难。运行脚本时,如中所述 https://github.com/jennybc/googlesheets我总是:

Error: could not find function "%>%"

我该如何解决这个问题?

可重现的例子:

下载:

devtools::install_github("jennybc/googlesheets")
require(googlesheets)

数据:

gap_key <- "1HT5B8SgkKqHdqHJmn5xiuaC04Ngb7dG9Tv94004vezA"
copy_ss(key = gap_key, to = "Gapminder")
gap <- register_ss("Gapminder")

发生错误:

oceania_csv <- gap %>% get_via_csv(ws = "Oceania")

【问题讨论】:

    标签: r r-googlesheets


    【解决方案1】:

    首先加载dplyr 包,它提供%&gt;% 运算符。这在您链接到的自述文件中注明了heresuppressMessages 是可选的):

    googlesheets 旨在与 %>% 管道运算符一起使用,并且在较小程度上与 dplyr 的数据争吵心态一起使用。此处的示例同时使用了这两种方法,但我们很快会开发一个小插图来显示普通香草 R 的用法。googlesheets 在内部使用 dplyr,但不需要用户这样做。

    library("googlesheets")
    suppressMessages(library("dplyr"))
    

    您可以使用 dplyr 安装

    install.packages("dplyr")
    

    有关管道运算符的更多信息,请参阅here (%&gt;%)。

    【讨论】:

    • 严格来说,magrittr 包提供了%&gt;% 运算符,但dplyr 导入并重新导出它,使其可供用户使用。你可以require(magrittr) 并且管道操作员应该可以工作。
    猜你喜欢
    • 1970-01-01
    • 2019-10-24
    • 2021-06-05
    • 1970-01-01
    • 2017-03-25
    • 1970-01-01
    • 2015-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多