I read in a public-use dataset that created dozens of temporary vectors in the process of building a final dataframe. Since this dataframe will be analyzed as part of a larger p
This should work.
source(file="script1.R")
rm(list=ls()[!sapply(mget(ls(),.GlobalEnv), is.data.frame)])
Breaking it down:
mget(ls())
gets all the objects in the global environment!sapply(..., is.data.frame
determines which is not a data.framerm(list=ls()[..]
removes only the objects that are not data.frames