[R] Repost: Expressions returned by GlobalEnv functions and package functions

Saptarshi Guha saptarshi.guha at gmail.com
Thu May 31 23:25:05 CEST 2012


Hello,
(Sorry for the repost, i am resending in plain text)

I have a function 'ewrap' (see below for definition).
It takes 3 expressions and returns another expression e.g.

map <- ewrap({
    len <- length(r$addon)
    rhcollect(len,1)
  })

becomes:

expression({
    NULL
    result <- mapply(function(.index, k, r) {
        {
            len <- length(r$addon)
            rhcollect(len, 1)
        }
    }, 1:length(map.values), map.keys, map.values)
    NULL
})
attr(,"class")
[1] "expression" "rhmr-map"

ewrap is defined in the GlobalEnv. In my package (Rhipe), a function
rhwrap has the exact same definition

rhwap <-  function(co1=NULL,before=NULL,after=NULL){
  co <- substitute(co1); before=substitute(before)
  j <- as.expression(bquote({
    .(BE)
    result <- mapply(function(.index,k,r){
      .(CO)
    },1:length(map.values),map.keys,map.values)
    .(AF)
  },list(CO=co,BE=before,AF=after)))
  class(j) <- c(class(j),"rhmr-map")
  j
}

but the following two are different,

map <- ewrap({
    len <- length(r$addon)
    rhcollect(len,1)
  })

and

map2 <- rhwrap({
    len <- length(r$addon)
    rhcollect(len,1)
  })

(because serialize(map,NULL) != serialize(map2,NULL))

I guess this is because both functions(ewrap and rhwrap) return an
environment in which they are defined and in the case
of rhwrap this is the Rhipe package namespace/environment (i'm not
sure what jargon i should use here).

So my questions are:

1. how do i inspect the extra information that rhwrap is adding to its
return value
2. How do i remove this, so that it behaves like ewrap


Thanks in advance
Saptarshi



More information about the R-help mailing list