Closed JohannesNE closed 6 months ago
Whoa, thank you for reporting! This seems like a very frequent use case.
First, here's a workaround until it's fixed:
Workaround option 1:
sq_nums <- function() {
# "import" functions from calling environment
make_nums2 = get("make_nums", envir = parent.frame())
make_nums2()^2
}
Workaround option 2:
sq_nums <- function() {
# Eval expression in calling environment
eval(expression(make_nums()^2), envir = parent.frame())
}
The problem is that sq_norms
look for make_nums
in the global environment (globalenv()
) but the main session is actually imported to an environment at level 3 inside the job::job()
and this is where the code is executed (try print(sys.nframe())
in your main session and inside the job). This is actually what rstudioapi::jobRunScript()
does.
Thank you for creating and maintaining this package!
My use case is (of course) a bit more complicated, so I would prefer not to change the multiple layers of user functions to make the workaround work. No problem! Until it's fixed, I'll just get a cup of coffee while my console is occupied :)
+1 for this. job::job()
is perfect for what I need to do. Unfortunately neither workaround works—the needed functions are in the global environment, which appears to be a couple levels up from the job parent, but remain inacessible even when specifying globalenv()
or .GlobalEnv
—and explicitly including functions with job::job(import)
also fails despite 114.2 MB of other things getting imported.
Not a coffee drinker, so I guess either I'm making a lot of code changes or running as many R separate sessions as I can keep track of and merging the results using save()
and load()
. 😀
This bug seems to have resolved itself!? Possibly via an update of RStudio and/or rstudioapi
. Can you confirm @JohannesNE and @twest820?
If it doesn't work with the CRAN version of job
, then try remotes::install_github("lindeloev/job")
. Compared to the CRAN version, it's just a bug-fix release. See NEWS.md.
job 0.3.1 is on CRAN now. I've added this "phenomenon" to the test suite and it passes on win/mac/linux. So I'm closing it for now. Please reopen if it persists!
Can you confirm @JohannesNE and @twest820?
Unfortunately I can't. This was enough of an adoption issue I never developed code relying on job. Cool that calls should flow now, though; I'll give it another try next time something in this direction comes up for coding in R (future does ok within it's use cases but I've found it tends to stop scaling around eight cores).
If I make a function (
fun1
), call that function from another function (fun2
), and callfun2
from a job,fun1
can not be found.Session info