lookup v0.0.0.9000

Lookup R function definitions, including compiled code, S3 and S4 methods

Provides a simple interface to lookup and print R function definitions, including C and C++ compiled code from .Call, .C, .Internal and .External calls. Also lookup of S3 and S4 generics, including a simple dialog to print any or all of the loaded methods for the generic.

Readme

lookup

Lookup R function definitions, including compiled code, S3 and S4 methods from packages installed locally, or from GitHub, CRAN or Bioconductor.

Travis-CI Build Status Coverage Status

luke

Installation

# install.packages("devtools")
devtools::install_github("jimhester/lookup")

See Setup for additional setup instructions.

Example

Normal Functions (with compiled code)

Imgur

S3 generics and methods

Imgur

S4 generics and methods

Imgur

In RStudio IDE

Imgur

Usage

# Lookup a function
lookup::lookup(body)
#> base::body [closure] 
#> function (fun = sys.function(sys.parent())) 
#> {
#>     if (is.character(fun)) 
#>         fun <- get(fun, mode = "function", envir = parent.frame())
#>     .Internal(body(fun))
#> }
#> <bytecode: 0x7fa65cada988>
#> <environment: namespace:base>
#> // c source: src/main/builtin.c#L255-L266
#> SEXP attribute_hidden do_body(SEXP call, SEXP op, SEXP args, SEXP rho)
#> {
#>     checkArity(op, args);
#>     if (TYPEOF(CAR(args)) == CLOSXP)
#>  return duplicate(BODY_EXPR(CAR(args)));
#>     else {
#>  if(!(TYPEOF(CAR(args)) == BUILTINSXP ||
#>       TYPEOF(CAR(args)) == SPECIALSXP))
#>      warningcall(call, _("argument is not a function"));
#>  return R_NilValue;
#>     }
#> }

# Can also open a browser at that function's location
lookup_browse()

Setup

lookup makes heavy use of the GitHub API, which has a rate limit of 60 requests per hour when unauthenticated. You can create a Personal access token with no scope, which will increase your limit to 5000 requests per hour.

Once you have generated a token, add it to your ~/.Renviron file or shell startup file and it will be automatically used for further requests.

GITHUB_PAT=7d8d0436835d1baXYZ1234

gh::gh("/rate_limit") can be used to query your current usage and limits.

Default printing

lookup can be used as a complete replacement for function printing by attaching the package. To make this the default simply add this to your .Rprofile.

if (interactive()) {
  suppressPackageStartupMessages(library(lookup))
}

If you do not want make this the default simply call lookup::lookup().

How this works

If a base R function is printed that calls compiled code the code is looked up using the R git mirror. If a CRAN package has compiled code it is looked up on the CRAN git mirror. If a package is installed with devtools::install_github() or devtools::install() the remote or local repository location is searched for the code.

This has been tested to work with .Internal, .External, .C, .Call and Rcpp calls.

Issues

This package uses a number of heuristics to find function definitions. This means it can fail in some cases, if you find a function that is not looked up properly, please open an issue.

Thanks

Functions in lookup

Name Description
lookup Lookup a function definiton
lookup_usage Search for code usage on CRAN
lookup_browse Browse a lookup
source_url Retrieve the source url(s) from a lookup object
No Results!

Details

License MIT + file LICENSE
LazyData true
Remotes jimhester/highlite, gaborcsardi/gh, hadley/memoise
LinkingTo Rcpp
RoxygenNote 6.0.1
Collate 'RcppExports.R' 'S3.R' 'rcpp.R' 'call.R' 'internal.R' 'external.R' 'github.R' 'highlight.R' 'lookup.R' 'package.R' 'registered_routines.R' 'utils.R'
Encoding UTF-8

Include our badge in your README

[![Rdoc](http://www.rdocumentation.org/badges/version/lookup)](http://www.rdocumentation.org/packages/lookup)