Learn R Programming

mvbutils (version 2.5.101)

my.package.path: Given a function in a loaded package, find the path of the package.

Description

Useful for finding the path of special files in a package. Usually this will be called inside a function which lives in a package. If the package has a namespace, the path object stored in the .__NAMESPACE__. environment is used; if not, the path attribute of the attached package in the search path is used. The package has to be loaded, of course. Doesn't work for things in baseenv().

Usage

my.package.path( func=sys.function( sys.parent()))

Arguments

func
a function in a package. If you're calling it from a function in that package, the default will usually do.

Value

  • Path: a character string, or NULL if not found.

Strange usage

If you are doing something weird, then the default func might not you work. Instead, you can set func manually beforehand, e.g.: me <- sys.function() my.path <- lapply( list( me), my.package.path)[[1]]

Examples

Run this code
my.package.path( ks.test)
mypack:::show.description.file <- function() as.cat( readLines(
    file.path( my.package.path(), 'DESCRIPTION')))

Run the code above in your browser using DataLab