futureverse / future.apply

:rocket: R package: future.apply - Apply Function to Elements in Parallel using Futures
https://future.apply.futureverse.org
211 stars 16 forks source link

Locally defined S3 methods are not automatically exported (was: function.type are not loaded as global variables) #18

Closed Rloveeee closed 5 years ago

Rloveeee commented 6 years ago

library("future.apply") plan(multiprocess, workers = 12) test=function(...){ UseMethod("test") } test.numeric=function(x){ return(x) } test.character=function(x){ return(x) } FUN=function(x) { test(x) } xx=future.apply::future_lapply(FUN=FUN,X=c(2,3))

=> It doesn't have test.numeric

I also have another one but I can't (yet) reproduce it on small code. (It can't find roll_sd from RcppRoll).

Best

HenrikBengtsson commented 6 years ago

I suspect this is related to https://github.com/HenrikBengtsson/globals/issues/2 - locally defined S3 methods (contrary to defining them in packages) are not automagically picked up as globals. If this is your problem, you can manually guide the future framework to export them by using:

FUN <- function(x) {
  ## Make sure locally defined S3 methods are found / exported
  test.numeric
  test.character

  test(x)
}

Two comments to increase chances to get replies:

Please cut'n'paste your output so it's non-ambiguous what the problem is. It also help, because by just looking at the output I, or others, might be able to reply must sooner - even without having sit in front of a computer trying to reproduce your problem. Also, make sure to share your sessionInfo() - that always helps when addressing questions/problems.

Also, please try to use Markdown formatting for readability. Below each GitHub comment box there's a link to https://guides.github.com/features/mastering-markdown/ with example how to do that.

Rloveeee commented 6 years ago

Ok, I ll do.

Thanks

2018-07-23 20:58 GMT+02:00 Henrik Bengtsson notifications@github.com:

I suspect this is related to HenrikBengtsson/globals#2 https://github.com/HenrikBengtsson/globals/issues/2 - locally defined S3 methods (contrary to defining them in packages) are not automagically picked up as globals. If this is your problem, you can manually guide the future framework to export them by using:

FUN <- function(x) {

Make sure locally defined S3 methods are found / exported

test.numeric test.character

test(x) }

Two comments to increase chances to get replies:

Please cut'n'paste your output so it's non-ambiguous what the problem is. It also help, because by just looking at the output I, or others, might be able to reply must sooner - even without having sit in front of a computer trying to reproduce your problem. Also, make sure to share your sessionInfo() - that always helps when addressing questions/problems.

Also, please try to use Markdown formatting for readability. Below each GitHub comment box there's a link to https://guides.github.com/ features/mastering-markdown/ with example how to do that.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/HenrikBengtsson/future.apply/issues/18#issuecomment-407164924, or mute the thread https://github.com/notifications/unsubscribe-auth/AQwLzk4vhYCzLN6Uy3oYvw_pucyPXyl_ks5uJhy_gaJpZM4VbflP .