在 R 中创建 gt table 时遇到问题
Having issues with creating a gt table in R
我收到以下错误,“错误:不知道如何使用 class quosures 的对象 select 行”
我已将其缩小到 R markdown 文件中的一段特定代码。如果我突出显示 from Sum_Adjusted to "seriesttls") 和 运行 selected 行,没有错误。是tab行组项甩掉了。
Sum_Adjusted <- Adjusted %>%gt(rowname_col = "seriesttls") %>%
tab_row_group(group = "Super Sectors",
rows = vars("Mining and logging","Construction","Manufacturing","Trade,
transportation, and utilities","Information","Financial activities","Professional and
business services","Education and health services","Leisure and hospitality","Other
services","Government"))
我希望通过查看代码,有人可以解释为什么我现在收到此错误,而不是过去十几次我遇到 运行 完全相同的代码。我无法在较小的示例中重现这一点。
str(Adjusted) 产生这个
tibble [12 x 7] (S3: tbl_df/tbl/data.frame)
$ seriesttls : chr [1:12] "Total nonfarm" "Mining and logging"
"Construction" "Manufacturing" ...
$ empces : num [1:12] 1335900 15000 91000 60200 282200 ...
$ MonthlyDifference: num [1:12] 4800 0 -1000 0 900 600 500 1500 0 1800 ...
$ AnnualDifference : num [1:12] 100900 200 -1900 5200 30600 ...
$ PercentGrowthRate: num [1:12] 0.0817 0.0135 -0.0205 0.0945 0.1216 ...
$ Max : num [1:12] 1442800 15800 146400 60300 282200 ...
$ oftotal : num [1:12] 1 0.0112 0.0681 0.0451 0.2112 ...
问题是 rows
应该是一个向量,因此而不是 vars
(可能已弃用),使用标准的 select-helpers 或者只是与 [=14 连接=] 如文档所述
rows -
The rows to be made components of the row group. Can either be a vector of row captions provided in c(), a vector of row indices, or a helper function focused on selections. The select helper functions are: starts_with(), ends_with(), contains(), matches(), one_of(), and everything().
我们可以做到
library(gt)
library(dplyr)
Adjusted %>%
gt(rowname_col = "seriesttls") %>%
tab_row_group(label = "Super Sectors",
rows = c("Mining and logging","Construction","Manufacturing","Trade,
transportation, and utilities","Information","Financial activities","Professional and
business services","Education and health services","Leisure and hospitality","Other
services","Government"))
使用可重现的例子
gtcars %>%
dplyr::select(model, year, hp, trq) %>%
dplyr::slice(1:8) %>%
gt(rowname_col = "model") %>%
tab_row_group(
label = "numbered",
rows = c("GT", "California"))
-输出
我收到以下错误,“错误:不知道如何使用 class quosures 的对象 select 行”
我已将其缩小到 R markdown 文件中的一段特定代码。如果我突出显示 from Sum_Adjusted to "seriesttls") 和 运行 selected 行,没有错误。是tab行组项甩掉了。
Sum_Adjusted <- Adjusted %>%gt(rowname_col = "seriesttls") %>%
tab_row_group(group = "Super Sectors",
rows = vars("Mining and logging","Construction","Manufacturing","Trade,
transportation, and utilities","Information","Financial activities","Professional and
business services","Education and health services","Leisure and hospitality","Other
services","Government"))
我希望通过查看代码,有人可以解释为什么我现在收到此错误,而不是过去十几次我遇到 运行 完全相同的代码。我无法在较小的示例中重现这一点。
str(Adjusted) 产生这个
tibble [12 x 7] (S3: tbl_df/tbl/data.frame)
$ seriesttls : chr [1:12] "Total nonfarm" "Mining and logging"
"Construction" "Manufacturing" ...
$ empces : num [1:12] 1335900 15000 91000 60200 282200 ...
$ MonthlyDifference: num [1:12] 4800 0 -1000 0 900 600 500 1500 0 1800 ...
$ AnnualDifference : num [1:12] 100900 200 -1900 5200 30600 ...
$ PercentGrowthRate: num [1:12] 0.0817 0.0135 -0.0205 0.0945 0.1216 ...
$ Max : num [1:12] 1442800 15800 146400 60300 282200 ...
$ oftotal : num [1:12] 1 0.0112 0.0681 0.0451 0.2112 ...
问题是 rows
应该是一个向量,因此而不是 vars
(可能已弃用),使用标准的 select-helpers 或者只是与 [=14 连接=] 如文档所述
rows - The rows to be made components of the row group. Can either be a vector of row captions provided in c(), a vector of row indices, or a helper function focused on selections. The select helper functions are: starts_with(), ends_with(), contains(), matches(), one_of(), and everything().
我们可以做到
library(gt)
library(dplyr)
Adjusted %>%
gt(rowname_col = "seriesttls") %>%
tab_row_group(label = "Super Sectors",
rows = c("Mining and logging","Construction","Manufacturing","Trade,
transportation, and utilities","Information","Financial activities","Professional and
business services","Education and health services","Leisure and hospitality","Other
services","Government"))
使用可重现的例子
gtcars %>%
dplyr::select(model, year, hp, trq) %>%
dplyr::slice(1:8) %>%
gt(rowname_col = "model") %>%
tab_row_group(
label = "numbered",
rows = c("GT", "California"))
-输出