Let's introduce two functions:
test_f <- function(df, var) {
  print(df$var)
}
test_s <- function(df, var) {
  print(df[, var])
}
And the df itself:
df <- data.frame(c(0:10))
colnames(df) <- "X"
What I'm missing when running, the $ version returns NULL, but [] prints the result correctly:
> test_f(df, "X")
NULL
> test_s(df, "X")
 [1]  0  1  2  3  4  5  6  7  8  9 10
 
    