Troubleshoot error with column identification

Hello - I'm a new R user and was trying to use final fit package to simplify some of my tables etc. https://www.r-bloggers.com/2018/05/elegant-regression-results-tables-and-plots-in-r-the-finalfit-package/

I keep running into an error with the code where it can't find the variable diabetes. Although when I list it, it is there in the dataset. I've pasted the code and error message below. Diabetes is a "yes/no" variable - could that be part of the issue?

Many thanks.

library(finalfit)
library(dplyr)
data(diabetesdata)
diabetes <- as.factor(diabetesdata[,"dm"])
explanatory = c("hdl", "age")
dependent =  "diabetes"  # diabetes as outcome
diabetesdata %>%
  summary_factorlist(dependent, explanatory, p=TRUE, add_dependent_label=TRUE)

list(diabetes). # I did this to check the variable and it's fine

Error: Can't subset columns that don't exist.
x Column diabetes doesn't exist.

I think the problem is that the variable diabetes exists but there is not a column named diabetes in the data frame diabetesdata. The function is looking inside the data frame. Try changing your definition of diabetes to

diabetesdata$diabetes <- as.factor(diabetesdata[,"dm"])

You can run

summary(diabetesdata)

just before and after that command to see that a new column is made.