The codetools package has functions for this purpose, eg findGlobals
findGlobals(f, merge=FALSE)[['variables']]
# [1] "x"
if we redefine the function to have a named argument x then no variables are returned.
f2 <- function(x){
x+1
}
findGlobals(f2, merge=FALSE)[['variables']]
# character(0)