Search
Question: BiocParallel on Windows: how should I pass (not exported) setReplace functions to bplapply?
0
gravatar for jcrodriguez
9 months ago by
jcrodriguez20
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);
    
    return(actRank);
}, 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 9 months ago by Martin Morgan ♦♦ 20k • written 9 months ago by jcrodriguez20
0
gravatar for Martin Morgan
9 months ago by
Martin Morgan ♦♦ 20k
United States
Martin Morgan ♦♦ 20k 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) 
standardGeneric("foo")
<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
        validObject(x)
        x
    }, v)
}
<environment: namespace:PkgA>

Signatures:
        x  
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) 
standardGeneric("xslot<-")
<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
    validObject(x)
    x
}
<environment: namespace:PkgA>

Signatures:
        x   value    
target  "A" "numeric"
defined "A" "numeric"

 

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

Help
Access

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