knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
Test package (proof of concept) for behavior of import package for S3 methods. Installation not recommended except to test that behavior.
Use library()
to load package
# catterpoc should not be loaded at start testthat::expect_error(catter_a("hello"), "could not find function") library(catterpoc) x <- catter_a("hello") x # print.catter_a not picked up x <- catter_b("hello") x # print.catter_b not picked up when loading package (even if .S3method was called) x <- catter_c("hello") x # print.catter_c is picked up correctly (because it is correctly exported in NAMESPACE) # Detach detach("package:catterpoc", unload=TRUE)
Import from package
# catterpoc should not be loaded at start testthat::expect_error(catter_a("hello"), "could not find function") import::from(catterpoc, catter_a, catter_b, catter_c) x <- catter_a("hello") x # print.catter_a not picked up x <- catter_b("hello") x # print.catter_b NOT picked up when importing from package (even if .S3method was called) x <- catter_c("hello") x # print.catter_c is picked up correctly (because it is correctly exported in NAMESPACE) rm("catter_a", "catter_b", "catter_c", pos="imports")
Import from script/module
# catterpoc should not be loaded at start testthat::expect_error(catter_a("hello"), "could not find function") import::from("R/catter.R", "catter_a", "catter_b", "catter_c", .character_only=TRUE) x <- catter_a("hello") x # print.catter_a not picked up x <- catter_b("hello") x # Here, it is picked up correctly (because .S3method was called in the module) x <- catter_c("hello") # Here, print.catter_c gets picked up only because a function of that name got # registered when loading the library, and it does not get detached even if package # has been unloaded. If this block is run in a fresh session, the print method # does NOT get picked up. x rm("catter_a", "catter_b", "catter_c", pos="imports")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.