Reputation: 556
I have R-markdown codes that used to work on my laptop properly. Now, when I try to knit them to HTML file, I get this error:
Error: Must supply a symbol or a string as argument.
Interestingly, my colleague says the codes work fine on her desktop computer. She is using windows.
This error comes up after the following lines of codes (also please see the screenshot):
acs <-
structure(list(`County Name` = c("U.S.", "Ohio", "Adams", "Allen",
"Ashland", "Ashtabula"), Year = c(2000, 2000, 2000, 2000, 2000,
2000), Sex = c("Male", "Male", "Male", "Male", "Male", "Male"
), `Age Group` = c("All", "All", "All", "All", "All", "All"),
`6th Grade or Less` = c(0.824, 0.038, 0.061, 0.012, 0.04,
0.031), `7th- 12th (No Diploma)` = c(0.085, 0.275, 0.343,
0.28, 0.283, 0.286), `High School Graduate` = c(0.037, 0.341,
0.347, 0.442, 0.436, 0.44), `Some College` = c(0.054, 0.171,
0.162, 0.149, 0.119, 0.148), `Bachelor's Degree` = c(NA,
0.097, 0.038, 0.067, 0.066, 0.053), `Graduate Degree` = c(NA,
0.077, 0.05, 0.049, 0.056, 0.041), `White Non-Hispanic` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `Black Non-Hispanic` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `Other Races Non-Hispanic in` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), Hispanic = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `Total 60+` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `Median Age for 60+` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `% of Population Age 60 & Older` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `% of Population` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `% of Population Living Alone` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `% of Grand Parents Living with Grand Children` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `% of Population with High School Diploma or Higher Degree` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `% of Population with College Degree` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `Median Income` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `% below 100% of Federal Povery Treshhold income` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `% Medicaid Eligible` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `% employed` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `Living Alone` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `0-100%` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `101-200%` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `201-300%` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `301-400%` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `>400%` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), Married = c(0.529,
0.752, 0.732, 0.774, 0.813, 0.724), `Widowed/Divorced/Separated` = c(0.168,
0.207, 0.22, 0.195, 0.153, 0.223), `Never Married` = c(0.303,
0.041, 0.047, 0.031, 0.034, 0.053), `At or Below Poverty Treshhold` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `Above Four Times Poverty Treshhold` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `Income to poverty_less 1` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `Income to poverty_less 1-1.99` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `Income to poverty_less 2-2.99` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `Income to poverty_less 3-3.99` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `Income to poverty_less 4+` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_)), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
edu.county<-acs %>%
filter(Sex == "Total", `Age Group`=="All", `County Name`%in% c(county, "Ohio"), Year == max(acs$Year))
edu.county$`County Name`<-factor(edu.county$`County Name`, levels = c("Ohio", county))
edu.county<-edu.county %>%
select(`6th Grade or Less`, `7th- 12th (No Diploma)`, `High School Graduate`,
`Some College`, `Bachelor's Degree`, `Graduate Degree`) %>%
gather(c(`6th Grade or Less`, `7th- 12th (No Diploma)`, `High School Graduate`,
`Some College`, `Bachelor's Degree`, `Graduate Degree`), EduPerc)
County<-rep(c("Ohio", county), 6)
edu.county<-cbind(edu.county, County)
Upvotes: 3
Views: 9435
Reputation: 556
As I mentioned in my question, the codes work fine on my colleague's desktop computer. She is using R 3.4.3 and I am using 3.5. version. I removed R from my laptop (not R studio) and installed a slightly older one (R version 3.3.3 (2017-03-06) -- "Another Canoe"). This solved the problem; I do not get the error message of "Error: Must supply a symbol or a string as argument" anymore. Thanks for everyone's input and advice.
Upvotes: 1
Reputation: 545618
I think the offender is in the following two lines:
gather(c(`6th Grade or Less`, `7th- 12th (No Diploma)`, `High School Graduate`,
`Some College`, `Bachelor's Degree`, `Graduate Degree`), EduPerc)
gather
expects a key and value column name, given as character strings. You are giving it a vector (c(…)
) of names. This doesn’t work, and it’s unclear what you are intending to do here. You may want something like the following:
… gather(`Education level`, EduPerc) …
Upvotes: 3