Permalink
Browse files

Experimenting with system.file

  • Loading branch information...
1 parent a10d777 commit 9ac5507ae3f85636b5f650bebc8a179cc6d9572d @hadley committed Jun 14, 2012
Showing with 31 additions and 1 deletion.
  1. +11 −1 R/package-env.r
  2. +8 −0 inst/tests/basic/DESCRIPTION
  3. +1 −0 inst/tests/basic/R/home.r
  4. +11 −0 inst/tests/test-env.r
View
12 R/package-env.r
@@ -87,5 +87,15 @@ clear_classes <- function(pkg = NULL) {
}
base_env <- function(pkg) {
- new.env(parent = emptyenv())
+ env <- new.env(parent = emptyenv())
+ env$system.file <- function(..., package = "base") {
+ if (package == pkg$package) {
+ file.path(pkg$path, ...)
+ } else {
+ system.file(..., package = package)
+ }
+ }
+
+ # new.env(parent = env)
+ env
}
View
8 inst/tests/basic/DESCRIPTION
@@ -0,0 +1,8 @@
+Package: basic
+Title: Test package
+Version: 0.1
+License: GPL-2
+Author: Hadley Wickham <h.wickham@gmail.com>
+Maintainer: Hadley Wickham <h.wickham@gmail.com>
+Description: Used for testing
+Collate: home.r
View
1 inst/tests/basic/R/home.r
@@ -0,0 +1 @@
+home <- function() system.file(package = "basic")
View
11 inst/tests/test-env.r
@@ -0,0 +1,11 @@
+context("Environment setup")
+
+test_that("system.file overriden", {
+ load_all("basic")
+
+ browser()
+ expect_that(home(), equals(normalizePath("basic")))
+
+
+ detach("package:basic")
+})

0 comments on commit 9ac5507

Please sign in to comment.