Running x <- c("data$var1", " data$var2") creates an object called x that contains the two listed character strings. x is a new object that has nothing to do with the data frame data or any columns within data. "data$var1" and "data$var2" are just character strings. They don't reference the data frame data or any of its columns, which you would reference with data$var1 or data$var2 (without the quotation marks). Running rm(x) just removes x (the vector containing the two character strings) and does not affect the data frame data at all.
If you want to remove the columns var1 and var2 from data you could do the following:
data = data[ , !(names(data) %in% c("var1", "var2"))]
To see what the %in% function is doing, trying running the following:
names(data) %in% c("var1", "var2")
!(names(data) %in% c("var1", "var2"))
names(data)[!(names(data) %in% c("var1", "var2"))]
To remove columns, you can also do the following:
library(tidyverse)
data = data %>% select(-var1, -var2)