getting error when making Function: Error in value.var %in% names(data) : object 'x' not found

We need a reproducible example (reprex)

I think though that we ma just teed some usable data. A handy way to supply sample data is to use the dput() function. See ?dput. If you have a very large data set then something like head(dput(myfile), 100) will likely supply enough data for us to work with.