-
Notifications
You must be signed in to change notification settings - Fork 37
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
madrat caching dependent on attached packages #219
Comments
As @fbenke-pik discovered, the situation is somewhat different.
|
The first is actually the policy we currently have in place. I think the 2nd solution does not work as madratAttach() in some cases needs to happen before .onLoad is being run. |
As in "an undocumented policy in contradiction to the stated 'R Language Rules'"?
|
Options for @fbenke-pik
|
Some comments / questions
|
I guess, the answer is: "Depends makes a package vulnerable to whatever other packages are loaded by the user." |
Actually, option 2 does not work for me. I tested on this branch: https://github.com/fbenke-pik/mrremind/tree/poc Starting a new R session, and loading the library via
|
what kind of stronger warning you have in mind? In general, I would be in favor of a solution which does not require depends in order to work. So far I just could not find any. If you have one which is working robustly I would be interested in it. |
Bloated search paths are mostly a nuisance, in my view. I am not convinced of the performance penalty @pascal-sauer claimed. Or more precisely, that it is relevant in this case. Name collisions between madrat-packages are a problem in any case—or not at all, depending on how you look at it. library(madrat)
setConfig(mainfolder = tempdir(), .verbose = FALSE)
dir.create(file.path(getConfig('sourcefolder'), 'Foo'))
library(Tom)
library(Dick)
getCalculations('read')
# type package call
# 1 Tau madrat madrat:::readTau
# 2 Foo Tom Tom:::readFoo
# 3 Foo Dick Dick:::readFoo
madrat:::fingerprint('readFoo')
# [1] "b4a51d22"
# attr(,"call")
# [1] "Tom:::readFoo"
# There were 50 or more warnings (use warnings() to see the first 50)
warnings()
# Warning messages:
# 1: In getCode(packages = packages, globalenv = globalenv) :
# Duplicate functions found: Dick:::readFoo, Tom:::readFoo! Laste entry will be used
# …
readSource('Foo', convert = FALSE)
# An object of class "magpie"
# , , 1
#
# year
# region [,1]
# Dick NA
#
# Warning messages:
# 1: In prepFunctionName(type = type, prefix = prefix) :
# More than one function found for type "Foo" and prefix "read". Use last occurrence (package "Dick")
# 2: In getCode(packages = packages, globalenv = globalenv) :
# Duplicate functions found: Tom:::readFoo, Dick:::readFoo! Laste entry will be used
# 3: In prepFunctionName(type = type, prefix = prefix, ignore = ignore) :
# More than one function found for type "Foo" and prefix "read". Use last occurrence (package "Dick") returning the hash of one but calling the other if several functions of the same name are found. And there is no way to call |
👉 |
No. Packages have internal search paths that are determined by the The situation is reversed. Using
So if packages keep re-exporting other packages, user scripts (and packages using them as |
It should outright fail. If a component cannot be hashed, then there is no way of determining the validity of the cache. "Es ist besser, nicht zu berechnen, als falsch zu berechnen." |
|
Thanks for the comments, Michaja. Very insightful.
Right, works as expected once the duplicate functions are removed.
I agree, at least for REMIND mr packages. I want it to fail and cause people to halt. If there are cases where this should not fail, we could make it a madrat config setting that defaults to false. I could draft a PR if @tscheypidi is open to move into this direction.
I just was made aware of it through our discussions here. But i find it in the madrat vignette as well: https://github.com/pik-piam/madrat/blob/master/vignettes/madrat.Rmd#L176-L180 The sentence you quoted might be misleading, but if you read the whole section |
Following Michaja's comments, I have created a PR for mrremind: pik-piam/mrremind#578 |
No. What one needs to do is "when creating a madrat-based package that uses functions of other madrat-based packages, these have to be declared as dependencies under |
This bug does not affect input data generation currently, but has the potential to screw it up in intractable ways.
For context, see pik-piam/mrremind#573, pik-piam/GDPuc#38 and this discussion.
Two facts can conspire to break the madrat caching for input data preparation.
madrat
and have their functions included in the fingerprinting for cache invalidation.Using plausible changes to the
mrdriver
package [↑] as an example,GDPuc
is loaded, but never attached. (So this is wrong.) Consequently,madrat
caching ingnorestoolConvertGDP()
in the fingerprinting, possibly leading to corrupted caches.Yes, there is a warning. But the warnings of the input data generation are ignored as a matter of policy, and truncated to 50 in any case.
Actually attaching, not only loading
GDPuc
yields different result:This is not an issue currently for input data generation, as
GDPuc
is imported explicitly in several packages (mrcommons
,mrfactors
,mrfaocore
,mrland
,mrremind
,mrvalidation
,piamInterfaces
). But should that be changed, caches will rot.The text was updated successfully, but these errors were encountered: