from: Import specific objects from packages

Description Usage Arguments Details Examples

View source: R/packages.R

Description

Import specific objects (e.g., functions) from a packages namespace.

Usage

1
from(pkg, import, as, envir = .GlobalEnv)

Arguments

pkg

Character string giving the name of the specific R package from which the objects will be imported.

import

Character vector specifying the particular objects to import from pkg.

as

Optional character vector specifying the names for which the imported objects will be assigned to. If missing, then the original objects (i.e., objects) names will be used.

envir

The environment for which the objects will be loaded into. The default is .GlobalEnv meaning load the objects into the global environment.

Details

Normally, one could implement this via object <- pkg::object, but that would require a new assignment for each object imported. This method allows one to import many objects at once from a particular package. It is also less error-prone then using pkg::object each time object is used.

Examples

1
2
3
4
5
6
7
# Importing package plyr's entire namespace can cause issues when package
# dplyr is loaded. Using importr can help mitigate these types of issues. The 
# following example assumes that both dplyr and plyr are installed.
library(dplyr)
from("plyr", import = c("ddply", "ldply"))
from("plyr", import = c("ddply", "ldply"), as = c(".ddply", ".ldply"))
identical(ddply, .ddply)

bgreenwell/bmisc documentation built on Sept. 24, 2019, 11:09 a.m.