Navigation Menu

Skip to content

Commit

Permalink
[tidyverse#407, tidyverse#499] import from methods to avoid error whe…
Browse files Browse the repository at this point in the history
…n not attached
  • Loading branch information
infotroph committed Oct 6, 2017
1 parent 9c86195 commit 28b5e34
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NAMESPACE
Expand Up @@ -266,11 +266,13 @@ exportMethods(show)
exportMethods(union)
import(stringr)
importFrom(Rcpp,sourceCpp)
importFrom(methods,"coerce<-")
importFrom(methods,"slot<-")
importFrom(methods,Arith)
importFrom(methods,Compare)
importFrom(methods,allNames)
importFrom(methods,callGeneric)
importFrom(methods,initialize)
importFrom(methods,is)
importFrom(methods,new)
importFrom(methods,setClass)
Expand Down
2 changes: 1 addition & 1 deletion R/package.r
Expand Up @@ -155,7 +155,7 @@
#' Easy with lubridate. Journal of Statistical Software, 40(3), 1-25.
#' \url{http://www.jstatsoft.org/v40/i03/}.
#' @import stringr
#' @importFrom methods setClass setGeneric new show allNames callGeneric is slot slot<- slotNames validObject Compare Arith
#' @importFrom methods setClass setGeneric new show allNames callGeneric is slot slot<- slotNames validObject Compare Arith initialize coerce<-
#' @importFrom utils packageVersion read.delim
#' @importFrom stats na.omit setNames update
#' @importFrom Rcpp sourceCpp
Expand Down
50 changes: 50 additions & 0 deletions tests/testthat/test-namespace.R
@@ -0,0 +1,50 @@
context("Namespace")

if (file.exists("../../00check.log")) {
# test was invoked by R CMD check -> package is already built
R_test_lib <- normalizePath("../..")
} else {
# We're testing in the source directory -> need to build and install
R_test_lib <- file.path(tempdir(), "Rlib")
dir.create(R_test_lib)
on.exit(unlink(R_test_lib, recursive = TRUE))
system2(
"R",
c("CMD install",
paste0("--library=", R_test_lib),
"--no-docs --no-help --no-demo --no-data --no-test-load",
normalizePath("../..")),
stdout = TRUE, stderr = TRUE)
}

do_Rscript <- function(expr) {
system2(
"Rscript",
args = c("--vanilla", "--default-packages=NULL", "-e", shQuote(expr)),
env = c("R_TESTS=", paste0("R_LIBS=", R_test_lib, ":", Sys.getenv("R_LIBS"))),
stdout = TRUE, stderr = TRUE)
}

test_that("methods is not attached", {
# Checking test assumptions.
# If this fails, namespace tests may not be needed anymore!
expect_match(
do_Rscript("'package:methods' %in% search()"),
"FALSE")
})

test_that("lubridate:: calls work when methods is not attached", {
expect_match( #314
do_Rscript(
"lubridate::round_date(as.POSIXct('2017-10-03 03:01:13Z'), 'minute')"),
as.character(round_date(as.POSIXct('2017-10-03 03:01:13Z'), 'minute')),
fixed = TRUE)
expect_match( #407
do_Rscript("lubridate::days(1)"),
as.character(days(1)),
fixed = TRUE)
expect_match( #499
do_Rscript("lubridate::dhours(22)"),
as.character(dhours(22)),
fixed = TRUE)
})

0 comments on commit 28b5e34

Please sign in to comment.