在RMarkdown中使用papaja和tableone时as.data.frame.character(x,stringsAsFactors = FALSE,...)中的错误

时间:2018-08-03 01:21:02

标签: r r-markdown kable papaja

我正在使用papaja在RMarkdown中创建APA格式的文档,但是,当我尝试创建文档时,apa_tables()函数会抛出错误。 em>

## reprex dataframe
head<-structure(list(age = c(30, 30, 24, 30, 29, 58), 
                   education = structure(c(5L, 2L, 2L, 2L, 2L, 3L), .Label = c("Less than high school", "High school diploma or GED", "Some college", "Associate's degree", "Bachelor's degree", "Professional or Masters degree", "Doctorate"), class = "factor"), 
                   gender = structure(c(2L, 2L, 2L, 2L, 2L, 1L), .Label = c("Male", "Female", "Non-binary", "Agender", "Androgynous", "Demigirl", "Transgender (preferred gender not stated)","NA"), class = "factor"), 
                   household_income = structure(c(5L, 3L, 6L, 1L, 2L, 2L), .Label = c("Less than $10,000", "$10,000 - $19,999","$20,000 - $29,999", "$30,000 - $39,999", "$40,000 - $49,999", "$50,000 - $59,999", "$60,000 - $69,999", "$70,000 - $79,999", "$80,000 - $89,999", "$90,000 - $99,999", "$100,000 - $149,999", "More than $150,000", "Prefer not to say"), class = "factor"), 
                   ideology_general = c(8L, 3L, 5L, 8L, 9L, 8L), 
                   ideology_economic = c(9L, 6L, 8L, 4L, 9L, 8L), 
                   ideology_social = c(7L, 4L, 3L, 6L, 9L, 8L), 
                   study = c("Climate Change", "Climate Change", "Flu vaccination", "Climate Change", "Climate Change", "Flu vaccination")), 
              row.names = c(NA,-6L), class = c("tbl_df", "tbl", "data.frame"))


## Use tableone to create a demographics table
tab<-print(tableone::CreateTableOne(vars = c("age", 
                             "education",
                             "gender",
                             "household_income", 
                             "ideology_general", 
                             "ideology_economic", 
                             "ideology_social"), 
                    data = head, strata = "study", test = FALSE), printToggle = FALSE)

## print table using papaja
papaja::apa_table(tab)

此代码引发错误

Error in as.data.frame.character(x, stringsAsFactors = FALSE, ...) : formal argument "stringsAsFactors" matched by multiple actual arguments

papaja::apa_table(tab)

如果我使用knitr :: kable(tab)而不是papaja :: apa_table(tab)创建表,这确实可以按预期运行,但是这使我没有其他所需的格式选项。

已解决:升级到新版本的papaja可以解决此问题。

0 个答案:

没有答案