[Rd] modifying data in a package
Ross Boylan
ross at biostat.ucsf.edu
Thu Mar 20 03:22:23 CET 2014
I've tweaked Rmpi and want to have some variables that hold data in the
package. One of the R files starts
mpi.isend.obj <- vector("list", 500) #mpi.request.maxsize())
mpi.isend.inuse <- rep(FALSE, 500) #mpi.request.maxsize())
and then functions update those variables with <<-. When run:
Error in mpi.isend.obj[[i]] <<- .force.type(x, type) :
cannot change value of locked binding for 'mpi.isend.obj'
I'm writing to ask the proper way to accomplish this objective (getting
a variable I can update in package namespace--or at least somewhere
useful and hidden from the outside).
I think the problem is that the package namespace is locked. So how do
I achieve the same effect?
http://www.r-bloggers.com/package-wide-variablescache-in-r-packages/
recommends creating an environment and then updating it. Is that the
preferred route? (It seems odd that the list should be locked but the
environment would be manipulable. I know environments are special.)
The comments indicate that 500 "should" be mpi.request.maxsize(). That
doesn't work because mpi.request.maxsize calls a C function, and there
is an error that the function isn't loaded. I guess the R code is
evaluated before the C libraries are loaded. The packages zzz.R starts
.onLoad <- function (lib, pkg) {
library.dynam("Rmpi", pkg, lib)
So would moving the code into .onLoad after that work? In that case,
how do I get the environment into the proper scope? Would
.onLoad <- function (lib, pkg) {
library.dynam("Rmpi", pkg, lib)
assign("mpi.globals", new.env(), environment(mpi.isend))
assign("mpi.isend.obj", vector("list", mpi.request.maxsize(),
mpi.globals)
work?
mpi.isend is a function in Rmpi. But I'd guess the first assign will
fail because the environment is locked.
Thanks.
Ross Boylan
More information about the R-devel
mailing list