Skip to content
Prev 2797 / 12125 Next

[R-pkg-devel] r-patched error

On 04/06/2018 7:34 AM, David Hugh-Jones wrote:
I'd worry a little bit about your "make_getter_setters" function:  it 
saves the result using

   lapply(names(funs), function (x) {
     assign(x, funs[[x]], envir = parent.frame(3)) # 3: 1 for 
function(x), 2 for lapply, 3 for the caller!
   })

That count of 3 looks like an implementation detail that could 
conceivably vary, for instance if the compiler decided to optimize out a 
call or two, or lapply's implementation changed.  (I suspect this isn't 
the cause of the error you saw, or you would have seen it a lot more: 
but I'd still fix it.)

I think a safer way to find the huxtable namespace is something like

huxtableNamespace <- .getNamespace("huxtable")

though this is advised against; a documented but less obvious way to do 
it would be

huxtableNamespace <- environment(huxtable)

The "huxtable" on the right is the function; most other functions in 
your package would also be fine, as long as you haven't done anything 
tricky to change their environments.

With one of those definitions, you could change your lapply() to

   lapply(names(funs), function (x) {
     assign(x, funs[[x]], envir = huxtableNamespace)
   })

 > Checks are passing fine on other platforms. Is this just a weirdness 
to do
 > with the changes in R 3.5.0 on Linux? Or does it indicate a real problem?

A possibility is memory corruption at the C level.  Since you don't have 
any C code in huxtable that couldn't be caused by what you did, but you 
might still be a victim of it.

Duncan Murdoch