Skip to content

testing the contents of an environment

4 messages · Tim Bergsma, jim holtman, Rolf Turner +1 more

#
Suppose I want to delete everything in my working directory that is not 
a function. It seems that

sapply(ls(),is.function)

always returns FALSE, because ls() returns objects of mode character. 
How do I evaluate is.function(), not on a character string, but on the 
object that character string represents?

Thanks,

Tim
#
Need to use 'get':
[1] "c.Factor"          "cls.console"       "date2POSIX"
"Default.par"       "delete.NULLs"
 [6] "f.apdex"           "f.area"            "f.axis"
"f.HHMMSS2hr"       "f.hr2HHMMSS"
[11] "f.integrate"       "f.queue"           "f.TimeAxis"
"file.size"         "function.print"
[16] "generate.stats"    "HrsInDay"          "level.plot"
"list.subset"       "ls.obj"
[21] "my.axis.POSIXct"   "my.func"           "my.ls"
"my.stats"          "plot.sar"
[26] "plot.srx.file"     "plotReset"         "poly.graph"
"poly.graph.legend" "poly.graph1"
[31] "print.wide"        "r.time.cvt"        "read.sar"
"ReadVMstat"        "sar.levelplot"
[36] "setParms"          "Setwd"             "time2POSIXct"
"unix2EXCEL"        "unix2POSIXct"
[41] "x.createColors"
c.Factor       cls.console        date2POSIX
Default.par      delete.NULLs
             TRUE              TRUE              TRUE
FALSE              TRUE
          f.apdex            f.area            f.axis
f.HHMMSS2hr       f.hr2HHMMSS
             TRUE              TRUE              TRUE
TRUE              TRUE
      f.integrate           f.queue        f.TimeAxis
file.size    function.print
             TRUE              TRUE              TRUE
TRUE              TRUE
   generate.stats          HrsInDay        level.plot
list.subset            ls.obj
             TRUE              TRUE              TRUE
TRUE              TRUE
  my.axis.POSIXct           my.func             my.ls
my.stats          plot.sar
             TRUE              TRUE              TRUE
TRUE              TRUE
    plot.srx.file         plotReset        poly.graph
poly.graph.legend       poly.graph1
             TRUE              TRUE              TRUE
TRUE              TRUE
       print.wide        r.time.cvt          read.sar
ReadVMstat     sar.levelplot
             TRUE              TRUE              TRUE
TRUE              TRUE
         setParms             Setwd      time2POSIXct
unix2EXCEL      unix2POSIXct
             TRUE              TRUE              TRUE
TRUE              TRUE
   x.createColors
             TRUE

        
On 9/27/07, Tim Bergsma <timb at metrumrg.com> wrote:

  
    
#
On 28/09/2007, at 6:52 AM, Tim Bergsma wrote:

            
sapply(ls(),function(x){is.function(get(x))})

One must distinguish between an object and its name.

(See ``Alice Through the Looking-Glass'' by Lewis Carroll aka Rev.  
Charles L. Dodgson. :-) )

			cheers,

				Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confidenti...{{dropped}}
#
On 9/27/07, Rolf Turner <r.turner at auckland.ac.nz> wrote:
A conceptually simpler alternative is

sapply(ls(), exists, mode = "function", inherits = FALSE)

-Deepayan