Skip to content

replace an expression with its value, or read macros

3 messages · Frank Tamborello, Thomas Lumley, Gabor Grothendieck

#
On Fri, Apr 8, 2011 at 11:45 AM, Franklin Tamborello II
<Franklin.Tamborello at uth.tmc.edu> wrote:
As a first note, most people who ask this sort of question would be
better off putting the sets of data into a single list rather than
named variables.

However, it is possible to do what you want.  One approach is to use
assign().  Another is to use bquote(), which is related to the Lisp
backquote macro: eval(bquote(.(s) <- read.delim(.(fn),header=FALSE)),
where .() is analogous to comma.

      -thomas
#
On Thu, Apr 7, 2011 at 7:45 PM, Franklin Tamborello II
<Franklin.Tamborello at uth.tmc.edu> wrote:
Here are a few possibilities:

# 1 - assign
assign(s, read.delim(fn, header = FALSE)

# 2 - .GlobalEnv
.GlobalEnv[[s]] <- read.delim(fn, header = FALSE)

# 3 - gsubfn's fn$ supports backticks
# Here we need gsubfn::fn to disambiguate the two fn's
library(gsubfn)
eval(gsubfn::fn$parse(text = " `s` <- read.delim(fn, header = FALSE) "))