rmarkdown error attempt to use zero-length variable name
Putting this as an answer for visibility: this happens if you try to run by selecting all in the Rmd and pressing enter like you would with a normal R script. RStudio tries to run this all as R code, including the markdown parts, leading to the errors you saw.
You can avoid this by running an individual chunk by clicking the green play button or by selecting one of the run options in the dropdown at the top of the Rmd editor.
R: attempt to use zero-length variable name in filter.data.frame
The error is because of column names with NA
values. You can either remove them.
library(dplyr)
qb_stats_all <- qb_stats_all %>%
select(-num, -(28:32)) %>%
filter(player != 'Player')
Or rename them to give them any appropriate column name.
names(qb_stats_all)[28:32] <- paste0('col', 1:5)
qb_stats_all <- qb_stats_all %>% filter(player != 'Player')
R Markdown won't knit; Error in parse attempt to use zero-length variable name
Found the answer. It's has to be saved as a .Rmd file, not an .R file. This is the case even if you selected your script as a Rmarkdown file within RStudio.
Related Topics
Creating an Equal Distance Spatial Grid in R
R: As.Posixct Timezone and Scale_X_Datetime Issues in My Dataset
R Aggregate Data.Frame with Date Column
R Finding Duplicates in One Column and Collapsing in a Second Column
How to Remove Rows with Nas Only If They Are Present in More Than Certain Percentage of Columns
Calculate Differences Between Rows Faster Than a for Loop
R Applying a Function to a Subset of a Data Frame
Axis-Labeling in R Histogram and Density Plots; Multiple Overlays of Density Plots
Order Dataframe for Given Columns
Return Rows Establishing a "Closest Value To" in R