2

I am using papaja to create an APA formatted document in RMarkdown, however the apa_tables() function is throwing an error when I try to create my document [sidenote: apa_tables() builds on kable()]

## 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)

This code throws the error

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

on the line with papaja::apa_table(tab)

This does run as expected if I create the table with knitr::kable(tab) instead of papaja::apa_table(tab) however that leaves me without other desired format options.

SOLVED: Upgrade to new version of papaja solved this issue.

neilfws
  • 32,751
  • 5
  • 50
  • 63
Emily Kothe
  • 842
  • 1
  • 6
  • 17
  • 2
    Hi Emily, I just tried the example and it works for me. Could you try updating to the latest version of `papaja` on GitHub (`devtools::install_github("crsh/papaja")`) and see if that fixes the problem? – crsh Aug 09 '18 at 11:44
  • 2
    Thanks for following up, this does solve it. I had upgraded papaja already but not realised it had fixed this bug – Emily Kothe Aug 10 '18 at 05:15
  • Great, glad it works now and thanks for getting back to me. – crsh Aug 10 '18 at 08:34

0 Answers0