[R] Using evaluate-deparse-substitute

About this list Date view Thread view Subject view Author view Attachment view

From: Adaikalavan Ramasamy (gisar@nus.edu.sg)
Date: Thu 20 Feb 2003 - 20:40:29 EST


Message-id: <024D6AEFCB92CB47BA1085751D184BB80105F20F@MBXSRV03.stf.nus.edu.sg>

Being the lazy soul I am, I wish to write a function to replace saying
ls(pattern=...) everytime. Here is what I have:

lsp <- function(x){
  y <- eval(deparse(substitute(x)))
  print(y) # CHECK

  print( ls(pattern = eval(y)) ) # TRY 1
  print( ls(pattern = eval(deparse(substitute(x)))) ) # TRY 2
}

Suppose I have
rubbish.in = rubbish.out = grub <- 1

I get the following when I try

> lsp(rub)
[1] "rub"
character(0)
character(0)

Can someone explain/help with this? Thank you very much.

______________________________________________
R-help@stat.math.ethz.ch mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Tue 01 Jul 2003 - 09:11:22 EST