Get type of all variables

后端 未结 6 767
我寻月下人不归
我寻月下人不归 2020-12-12 12:37

In R, I\'d like to retrieve a list of global variables at the end of my script and iterate over them. Here is my code

#declare a few sample variables
a<-1         


        
6条回答
  •  醉酒成梦
    2020-12-12 13:27

    Designed to do essentially the inverse of what you wanted, here's one of my toolkit toys:

     lstype<-function(type='closure'){
    inlist<-ls(.GlobalEnv)
    if (type=='function') type <-'closure'
    typelist<-sapply(sapply(inlist,get),typeof)
    return(names(typelist[typelist==type]))
    }
    

提交回复
热议问题