import: Import a script or evaluate expression without the Global...

Description Usage Arguments Value Examples

View source: R/import.R

Description

This function isolates R scripts and code, so they can attach libraries and load namespaces without affecting other scripts or the Global Environment. Importantly, this isolation makes the environment returned like an R package, in that changes to the Global Environment will not affect it.

Usage

1
import(file, chdir = TRUE)

Arguments

file

path to source file, or code to evalue. May also be a URL.

chdir

passed directly to source function.

Value

the environment in which the code was evaluated

Examples

1
2
3
4
5
6
7
8
module <- import({
 library(MASS)
 gen_data <- function() mvrnorm(10, 0, 1)
})
module$gen_data()                       # can use MASS::mvrnorm
stopifnot(exists("mvrnorm") == FALSE)   # MASS package not attached
mvrnorm <- NULL
module$gen_data()                       # still works

machow/importr documentation built on May 21, 2019, 10:51 a.m.