Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't run pMincApply example code: object 'fun' of mode 'function' was not found #299

Open
gdevenyi opened this issue Jan 4, 2022 · 11 comments

Comments

@gdevenyi
Copy link
Contributor

gdevenyi commented Jan 4, 2022

testdir = getRMINCTestData() 
gf <- read.csv(paste0(testdir, "test_data_set.csv")
ma <- mincApply(gf$jacobians_fixed_2,quote(mean(x))); 
mincWriteVolume(ma, "means.mnc")
### run the whole thing in parallel on the local machine
testFunc <- function (x) { return(c(1,2))}
pout <- pMincApply(gf$jacobians_fixed_2, 
                   quote(testFunc(x)),
                   workers = 4,
                   global = c('gf','testFunc'),
					local=T)
mincWriteVolume(pout, "pmincOut.mnc")
Error in get(as.character(FUN), mode = "function", envir = envir) : 
  object 'fun' of mode 'function' was not found
@bcdarwin
Copy link
Member

bcdarwin commented Jan 4, 2022

Having not looked into this yet, I wonder whether we still support the rather hackish quote(...(x)) syntax or whether it should just be mincApply(..., mean), etc.

@gdevenyi
Copy link
Contributor Author

gdevenyi commented Jan 4, 2022

We have tried both. The error is identical.

@bcdarwin
Copy link
Member

bcdarwin commented Jan 6, 2022

I have reproduced this behaviour with R 3.6.x and develop RMINC which otherwise passes the test suite. However,

pMincApply(gf$jacobians_fixed_2, testFunc, workers = 4, local = TRUE)

works correctly. If there's some other option combination without using quote which fails unexpectedly, please let me know.

Also, where in the documentation have you found this example? The test suite doesn't test pMincApply with quote, which I am tempted to consider a deprecated mode anyway (although supporting dplyr function syntax ~ . etc or even our lenses package's extended x ~ x + 2 syntax would be nice).

@gdevenyi
Copy link
Contributor Author

gdevenyi commented Jan 6, 2022

However,

I didn't know to try testFunc bare. We were using testfunc(x) without quote. This works! Hurrah!

Also, where in the documentation have you found this example?

The first entry in examples here, https://rdrr.io/github/Mouse-Imaging-Centre/RMINC/man/mincApply.html

@bcdarwin
Copy link
Member

bcdarwin commented Jan 7, 2022

Made some minor updates to the source documentation in 807ffc5, which should be reflected downstream after the next release (when we regenerate the docs).

@bcdarwin bcdarwin closed this as completed Jan 7, 2022
@gdevenyi
Copy link
Contributor Author

gdevenyi commented Jan 7, 2022

Sorry to follow up again, we're having new issues with pMincApply and I'm not sure what to do

The goal here is to attempt to solve #298 by writing our own code.

plslmer <- function(x, data) {
  mydata = cbind(data,x)
    eff = coef(lmer(x ~time_month + (time_month||Id), data = mydata,REML = T, lmerControl(optimizer ="Nelder_Mead")))
    return(c(eff$Id$`(Intercept)`,eff$Id$time_month))
} 

testrun <- pMincApply(data$jacobians, plslmer, workers = 4 
                      , local = T, tinyMask = T, global=c("data","plslmer")) 

But we get this:

Screen Shot 2022-01-06 at 5 29 53 PM

@bcdarwin
Copy link
Member

bcdarwin commented Jan 7, 2022

I think pMincApply expects a single-argument function; assuming your handling of the coefficients is correct, what about

plslmer <- function (data) function (x) { ... }

testrun <- pMincApply(data$jacobians, plslmer(data), ...)

although I'm not sure exactly how this interacts with global but maybe for local = T it doesn't matter.

@bcdarwin bcdarwin reopened this Jan 7, 2022
@gdevenyi
Copy link
Contributor Author

gdevenyi commented Jan 8, 2022

Sadly your suggestion produces the same error.

@bcdarwin
Copy link
Member

So in order, I would try: (i) look for more informative errors in the log files; (ii) try mincApply instead to see if this fails in the same way; (iii) create a reprex we can look at.

@jasonlerch
Copy link
Contributor

I will try and look at this tonight/tomorrow. A reprex would be handy, but if I think there's enough in this thread to get a handle on what you're trying to do even without one.

@gdevenyi
Copy link
Contributor Author

I've tried to generate a reproducer using the test data and been unable to. Looking into how to provide a pared down dataset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants