Question: BiocParallel on Windows: how should I pass (not exported) setReplace functions to bplapply?
gravatar for jcrodriguez
19 months ago by
jcrodriguez20 wrote:

Hi everyone!
I was having an issue similar as BiocParallel on Windows : cannot find my functions when using SnowParam
My problem was that I used inside my bplapply function, some not exported functions (designMatrix) from my package. Actually, this was solved by passing them/it as a parameter to the bplapply function:

calcRes <- bplapply(1:ncol(all_perms), function(i, designMatrix) {
    permDesign <- designMatrix(fit_options)[all_perms[,i],];
    new_fit_options <- fit_options;
    new_fit_options@design_matrix <- permDesign;
    # designMatrix(new_fit_options) <- permDesign;
    actRank <- rankFunction(data, new_fit_options);
}, designMatrix=designMatrix, BPPARAM=bp_param);

However, as you can see in my code I am having to use the '@' slot accessor, while I have the setReplaceMethod defined for it (look at the commented line).
Is there any way to pass my designMatrix<- function?
I have been trying different ways with no success.

thanks everyone!
Rodriguez, Juan C.

ADD COMMENTlink modified 19 months ago by Martin Morgan ♦♦ 22k • written 19 months ago by jcrodriguez20
gravatar for Martin Morgan
19 months ago by
Martin Morgan ♦♦ 22k
United States
Martin Morgan ♦♦ 22k wrote:

You're asking about package development, and the right forum for that is the bioc-devel mailing list.

I guess this is your MIGSA package. What's an easily reproduced example showing the error? Modulo special circumstances, packages using non-exported methods should 'just work' for the reasons outlined in the answer you cite -- the function is defined in the environment in which the bplapply() is called. I made an example in PkgA (note the 'bplapply' branch) where foo() is an exported generic and the update slotx<- is not. I have

> library(PkgA)
> BiocParallel::register(cl <- BiocParallel::bpstart(BiocParallel::SnowParam(2)))
> foo(A(0), 1)[[1]]
An object of class "A"
Slot "x":
[1] 1

where foo is an exported method

> foo
standardGeneric for "foo" defined from package "PkgA"

function (x, v) 
<environment: 0x34031c0>
Methods may be defined for arguments: x
Use  showMethods("foo")  for currently available ones.
> getMethod("foo", "A")
Method Definition:

function (x, v) 
    tasks <- replicate(2, x)
    bplapply(tasks, function(x, v) {
        xslot(x) <- v
    }, v)
<environment: namespace:PkgA>

target  "A"
defined "A"

and xslot<- is not

> `xslot<-`
Error: object 'xslot<-' not found
> PkgA:::`xslot<-`
standardGeneric for "xslot<-" defined from package "PkgA"

function (x, value) 
<environment: 0x33c6a98>
Methods may be defined for arguments: x, value
Use  showMethods("xslot<-")  for currently available ones.
> getMethod("xslot<-", c("A", "numeric"), where=getNamespace("PkgA"))
Method Definition:

function (x, value) 
    x@x <- value
<environment: namespace:PkgA>

        x   value    
target  "A" "numeric"
defined "A" "numeric"


ADD COMMENTlink written 19 months ago by Martin Morgan ♦♦ 22k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.2.0
Traffic: 289 users visited in the last hour