Functions to remove items from the global environment in R
#' Remove everything except functions
#'
#' Remove everything from the global environment except functions
#' @export
rm.except.fn <- function(){
rm(list = setdiff(ls(envir = .GlobalEnv), lsf.str(envir = .GlobalEnv)), envir = .GlobalEnv)
}
#' Remove only functions
#'
#' Remove functions from the global environment
#' @export
rm.fn <- function(){
rm(list=lsf.str(envir = .GlobalEnv), envir = .GlobalEnv)
}
#' Remove everything except...
#'
#' Remove everything from the global environment except named element. No default.
#' @param x Character vector of elements to be kept. No default
#' @export
rm.all.except <- function(x){
x <- c("rm.all.except",x)
rm(list = ls(envir = .GlobalEnv)[!ls(envir = .GlobalEnv) %in% x], envir = .GlobalEnv)
}