Comments (11)
I completely agree.
We should just use ::
-syntax to access functions from suggested dependencies used for testing, and avoid attaching packages to search path.
That's going to be a lot of work, though, but worth it in the long run.
from easystats.
Nope, it's not enough:
library(testthat)
test_that("foo 1", {
print("as.matrix.get_predicted" %in% methods(as.matrix))
})
#> [1] FALSE
#> ── Skip (???): foo 1 ───────────────────────────────────────────────────────────
#> Reason: empty test
test_that("foo 2", {
withr::local_package("insight")
})
#> ── Skip (???): foo 2 ───────────────────────────────────────────────────────────
#> Reason: empty test
test_that("foo 3", {
print("as.matrix.get_predicted" %in% methods(as.matrix))
})
#> [1] TRUE
#> ── Skip (???): foo 3 ───────────────────────────────────────────────────────────
#> Reason: empty test
withr::local_package()
calls detach()
under the hood, and the docs of detach()
say:
If a package has a namespace, detaching it does not by default unload the namespace (and may not even with unload = TRUE)
I think we're doing the best we can about this
from easystats.
Using ::
will probably solve the problem for functions exported by other packages but methods will still be available in the namespace so it won't solve everything (but I'm actually not sure we can do something to solve everything).
Also, this basically means reverting skip_if_not_or_load_if_installed()
to skip_if_not_installed()
+ ::
. Is there an easy way to revert some commits, even made a few days/weeks ago?
from easystats.
You can right click on the commit in the history in the GitHub desktop app (and maybe web interface) and choose to revert it.
git revert
is the equivalent terminal command I think
from easystats.
I have cleaned up tests in {see}
to address this issue (easystats/see#280).
from easystats.
Do we need to change the behavior of skip_if_not_or_load_if_installed() (cf #350) because it calls library()?
Actually, we should just get rid of that helper and just go back skip_if_not_installed()
.
Note that #350 was created in a different context. Most of our tests don't use ::
to access functions from soft deps, and also don't explicitly load datasets from soft deps with data()
, and so it was necessary to use require()
calls. Additionally, we also wanted to reduce noise in tests due to loading these different packages, and so skip_if_not_or_load_if_installed()
seemed like a good solution at the time.
If we want to use only skip_if_not_installed()
, then we need to make sure all used functions are namespaced and datasets are explicitly loaded. That's why I said this is going to be a lot of work.
from easystats.
If we adopt this discipline, clutter in unit test logs (e.g.) would also disappear.
from easystats.
If we absolutely must load some packages in a test file, it's a good idea to unload the namespace at the end of the test file (cf. easystats/parameters@3912175).
from easystats.
I find that using namespacing instead of loading for rstanarm
does not work most of the time. It's really funky. It tries to call functions that the script is not calling, but cannot find them. So they are used internally. Even defining those functions manually like stan_glmer <- rstanarm::stan_glmer
results in more errors like:
Unable to refit the model with standardized data.
Try instead to standardize the data (standardize(data)) and refit the
model manually.
So I am loading it for those instances. But I wonder if someone found a way to make it work with namespacing somehow?
(same for survival
package and Surv <- survival::Surv
)
from easystats.
In the section on self-contained tests, R Packages book recommends using withr::local_package()
to solve this issue.
But, IINM, @etiennebacher observed that that doesn't always work, right?
from easystats.
I think we have done everything we can here and there is not much to do.
from easystats.
Related Issues (20)
- Adding links to `see` vignettes in individual packages HOT 1
- Move from GPL-3 to MIT license HOT 8
- Figure out why total download counts are not included in the README table HOT 1
- Namespace error with sjPlot after installing easy stats HOT 3
- Use the new `check_if_installed()` with `.get_dep_version()` in all easystats packages HOT 1
- Should we leave out `date` and `author` from vignette metadata?
- Collect roxygen import tags and re-exports in a single location HOT 3
- Use `\donttest` instead of `\dontrun` tag for skipping examples on CRAN machines HOT 6
- Next meta-package CRAN release HOT 6
- Going workflow green HOT 2
- Surprising behaviour of tests on Windows in some specific contexts HOT 5
- Getting rid of a warning in a vignette HOT 2
- Check that the tests don't change the global state
- Running tests on 2 cores only HOT 6
- Enable required workflows? HOT 6
- Discussion: Bump minimum needed R version to `R 4.0` across the ecosystem? HOT 56
- Consistency of arguments across packages, in particular `by`, `group` and `group_by`. HOT 12
- Bump minimum needed R version to `R 4.0` in `DESCRIPTION` HOT 1
- Predicted values & text report error for model_dashboard(lmerTest::lmer model)
- Build favicons for pkgdown website locally HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from easystats.