When writing R functions always remind yourself to think about if it can happen that you accidentally just select one column of a data.frame. This will result in vector which might not be what you expect in the following code. One good practice is to always use drop=FALSE when you intend to get a data.frame and use the [[]] notation if you expect a vector.

df = data.frame(a = 1:3, b = letters[1:3])
cols = c("a")

Lets assume cols is a vector which only sometimes has the length one, then we would do the following:

df[, cols, drop=FALSE]
##   a
## 1 1
## 2 2
## 3 3

And to purposefully select a vector:

## [1] 1 2 3