import

An Import Mechanism For R

https://github.com/rticulate/import

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 9 committers (11.1%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.7%) to scientific vocabulary

Keywords

cran r
Last synced: 6 months ago · JSON representation

Repository

An Import Mechanism For R

Basic Info
Statistics
  • Stars: 228
  • Watchers: 7
  • Forks: 14
  • Open Issues: 5
  • Releases: 5
Topics
cran r
Created almost 11 years ago · Last pushed 10 months ago
Metadata Files
Readme Changelog License

README.Rmd

---
output: github_document
---

# import 


[![CRAN status](https://www.r-pkg.org/badges/version/import)](https://CRAN.R-project.org/package=import)
[![CRAN status shields](https://img.shields.io/badge/Git-`r desc::desc_get_version() `-success)](https://github.com/rticulate/import)
[![R build status](https://github.com/rticulate/import/workflows/R-CMD-check/badge.svg)](https://github.com/rticulate/import/actions)


# An Import Mechanism For R

The import package is intended to simplify the way in which functions from
external packages or modules are made available for use in R scripts. Learn more
on the [package website](https://import.rticulate.org/), by reading
[`vignette("import")`](https://import.rticulate.org/articles/import.html), or
using the help (`?import::from`).

## Introduction

The typical way of using functionality exposed by a package in R scripts is to
load (and attach) the entire package with `library()` (or `require()`). This can
have the **undesirable effect of masking objects** in the user's search path and
can also make it difficult and **confusing to identify** what functionality
comes from which package when using several `library` statements.

The `import` package provides a simple alternative, allowing the user specify in
a concise way exactly which objects. For example, the `Hmisc` package exposes
over four hundred functions. Instead of exposing all of those functions, someone
who only needs access to, say the `impute()` and the `nomiss()` functions, can
import those functions only:

```R
import::from(Hmisc, impute, nomiss)
```

For more on the motivation behind the package, see 
[vignette("import")](https://import.rticulate.org/articles/import.html)


## Installation

Install the release version of `import` from CRAN using `pak` or
`install.packages()`:

```R
pak::pak("import")
  # or
install.packages("import")
```

Install the development version of `import` from GitHub using `pak` or
`devtools`:

```R
pak::pak("rticulate/import")
  # or
devtools::install_github("rticulate/import")
```

## Usage

### Importing functions from R packages

The most basic use case is to import a few functions from package (here the
`psych` package):

```R
import::from(psych, geometric.mean, harmonic.mean)
geometric.mean(trees$Volume)
```

If one of the function names conflicts with an existing function (such as
`filter` from the `dplyr` package) it is simple to rename it:

```R
import::from(dplyr, select, arrange, keep_when = filter)
keep_when(mtcars, hp>250)
```

Use `.all=TRUE` to import all functions from a package. If you want to rename
one of them, you can still do that:

```R
import::from(dplyr, keep_when = filter, .all=TRUE)
```

To omit a function from the import, use `.except` (which takes a character
vector):

```R
import::from(dplyr, .except=c("filter", "lag"))
```

Note that `import` tries to be smart about this and assumes that if you are
using the `.except` parameter, you probably want to import everything you are
_not_ explicitly omitting, and sets the `.all` parameter to `TRUE`. You can
still override this in exceptional cases, but you seldom need to.

These and other examples are discussed in more detail in the 
[Importing from Packages](https://import.rticulate.org/articles/import.html#importing-from-packages)
section of the package vignette.

### Importing Functions from "Module" Scripts

The `import` package allows R files to be used as "modules" from which functions
are loaded. For example, the file
[sequence_module.R](https://raw.githubusercontent.com/rticulate/import/master/man/examples/sequence_module.R) 
contains several functions calculating terms of mathematical sequences. It is
possible to import from such files, just as one imports from packages:

```R
import::from(sequence_module.R, fibonacci, square, triangular)
```

Renaming, as well as the `.all` and `.except` parameters, work in the same way
as for packages:

```R
import::from(sequence_module.R, fib=fibonacci, .except="square")
```

These and other examples are discussed in more detail in the 
[Importing from Modules](https://import.rticulate.org/articles/import.html#importing-functions-from-module-scripts) 
section of the package vignette.

### Choosing where import looks for packages or modules

The `import` package will by default use the current set of library paths, i.e.
the result of `.libPaths()`. It is, however, possible to specify a different set
of library paths using the `.library` argument in any of the `import` functions,
for example to import packages installed in a custom location, or to remove any
ambiguity as to where imports come from.

Note that in versions up to and including `1.3.0` this defaulted to use only the
*first* entry in the library paths, i.e. `.library=.libPaths()[1L]`. We believe
the new default is applicable in a broader set of circumstances, but if this
change causes any issues, we would very much appreciate hearing about it.

When importing from a module (.R file), the directory where `import` looks for
the module script can be specified with the with `.directory` parameter. The
default is `.` (the current working directory).

### Choosing where the imported functions are placed

By default, imported objects are placed in a separate entity in the search path
called "imports". One can also specify which names to use in the search path and
use several to group imports:

```R
import::from(magrittr, "%>%", "%$%", .into = "operators") 
import::from(dplyr, arrange, .into = "datatools")
```

If using custom search path entities actively, one might prefer the alternative
syntax (which does the same but reverses the argument order):

```R
import::into("operators", "%>%", "%$%", .from = magrittr)
import::into("datatools", arrange, .from = dplyr)
```

If it is desired to place imported objects in the current environment, use
`import::here()`:

### More advanced usage

The `import` package is designed to be simple to use for basic cases, so it uses
symbolic evaluation to allow the names of packages, modules and functions to be
entered without quotes (except for operators, such as `"%>%"` which must be
quoted). However, this means that it calling a variable containing the name of a
module, or a vector of functions to import, will not work. For this use case,
you can use the `.character_only` parameter:

```R
module_name <- "../utils/my_module.R"

# Will not work (import will look for a package called "module_name")
import::from(module_name, foo, bar)

# This will correctly import the foo() and bar() functions from "../utils/my_module.R"
import::from(module_name, foo, bar, .character_only=TRUE)
```

The `.character_only` parameter is covered in more detail in the 
[Advanced Usage](https://import.rticulate.org/articles/import.html#advanced-usage) 
section of the package vignette, which also describes how you can import from
module scripts stored online with the help of the `pins` package, or achieve
python-like imports with the help of `{}` notation for environments in the
`.into` parameter.

# Contributing

Contributions to this project are welcome. Please start by opening an issue or
discussion thread. New features are added conservatively based on supply (is
anyone willing to contribute an implementation of the feature?), demand (how
many people seem to need a new feature?), and last, but not least, by whether a
feature can be implemented without breaking backwards compatibility.

- Created and authored by [@smbache](https://github.com/smbache)
- Currently maintained by [@torfason](https://github.com/torfason)
- Code contributions by 
  [@awong234](https://github.com/awong234), 
  [@brshallo](https://github.com/brshallo), 
  [@flying-sheep](https://github.com/flying-sheep), 
  [@hutch3232](https://github.com/hutch3232),
  [@J-Moravec](https://github.com/J-Moravec), 
  [@klmr](https://github.com/klmr),
  [@mschilli87](https://github.com/mschilli87),
  [@olivroy](https://github.com/olivroy)
  [@aramirezreyes](https://github.com/aramirezreyes)
  
*(Did we forget to add you? If so, please let us know!)*

# See also:

- Some of the use cases for `import` can now be handled directly in base R using
  the new `exclude` and `include.only` arguments of `library()` and `require()`
- For an interesting but slightly different idea of Python-like modules for R, 
  see the [box](https://klmr.me/box/) package by
  [@klmr](https://github.com/klmr) (previously called
  [modules](https://github.com/klmr/modules)).
- Another approach, focused on treating the use of functions with naming 
  conflicts as explicit errors is the
  [conflicted](https://github.com/r-lib/conflicted) package by
  [@hadley](https://github.com/hadley).

Owner

  • Name: rticulate
  • Login: rticulate
  • Kind: organization

GitHub Events

Total
  • Issues event: 3
  • Watch event: 4
  • Delete event: 1
  • Issue comment event: 2
  • Push event: 18
  • Pull request event: 4
  • Fork event: 1
  • Create event: 2
Last Year
  • Issues event: 3
  • Watch event: 4
  • Delete event: 1
  • Issue comment event: 2
  • Push event: 18
  • Pull request event: 4
  • Fork event: 1
  • Create event: 2

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 96
  • Total Committers: 9
  • Avg Commits per committer: 10.667
  • Development Distribution Score (DDS): 0.604
Past Year
  • Commits: 10
  • Committers: 2
  • Avg Commits per committer: 5.0
  • Development Distribution Score (DDS): 0.3
Top Committers
Name Email Commits
smbache s****n@s****k 38
Magnus Thor Torfason m@z****t 34
Paul Donnelly d****a@g****m 12
Alec Wong a****5@c****u 5
Jiří Moravec j****c@g****m 3
Konrad Rudolph k****h@g****m 1
Stefan Bache s****e@S****l 1
Philipp A f****p@w****e 1
Bryan Shalloway 3****o 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 63
  • Total pull requests: 33
  • Average time to close issues: 9 months
  • Average time to close pull requests: about 1 month
  • Total issue authors: 34
  • Total pull request authors: 11
  • Average comments per issue: 5.13
  • Average comments per pull request: 1.79
  • Merged pull requests: 27
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 3
  • Pull requests: 3
  • Average time to close issues: 18 days
  • Average time to close pull requests: about 5 hours
  • Issue authors: 3
  • Pull request authors: 2
  • Average comments per issue: 3.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 3
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • torfason (15)
  • hutch3232 (4)
  • mmuurr (3)
  • smbache (3)
  • vnijs (3)
  • J-Moravec (2)
  • brshallo (2)
  • krlmlr (2)
  • flying-sheep (2)
  • chunyunma (2)
  • awong234 (2)
  • jonasfreimuth (1)
  • aramirezreyes (1)
  • vdanglse (1)
  • leeper (1)
Pull Request Authors
  • torfason (20)
  • hutch3232 (5)
  • smbache (4)
  • J-Moravec (3)
  • aramirezreyes (2)
  • olivroy (2)
  • flying-sheep (1)
  • brshallo (1)
  • awong234 (1)
  • ashiklom (1)
  • klmr (1)
Top Labels
Issue Labels
fixed-in-main (13) maintenance (6) wontfix (5) enhancement (4) help wanted (3) fixed-in-dev (2) duplicate (1) bug (1)
Pull Request Labels
fixed-in-dev (2) wontfix (1)

Packages

  • Total packages: 2
  • Total downloads:
    • cran 3,443 last-month
  • Total docker downloads: 82,754
  • Total dependent packages: 14
    (may contain duplicates)
  • Total dependent repositories: 44
    (may contain duplicates)
  • Total versions: 13
  • Total maintainers: 1
proxy.golang.org: github.com/rticulate/import
  • Versions: 6
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.4%
Average: 5.6%
Dependent repos count: 5.8%
Last synced: 6 months ago
cran.r-project.org: import

An Import Mechanism for R

  • Versions: 7
  • Dependent Packages: 14
  • Dependent Repositories: 44
  • Downloads: 3,443 Last month
  • Docker Downloads: 82,754
Rankings
Stargazers count: 2.0%
Dependent repos count: 3.8%
Dependent packages count: 4.2%
Forks count: 4.8%
Downloads: 5.6%
Average: 6.0%
Docker downloads count: 15.9%
Maintainers (1)
Last synced: 6 months ago

Dependencies

DESCRIPTION cran
  • knitr * suggests
  • magrittr * suggests
  • rmarkdown * suggests
  • testthat * suggests
.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v2 composite
  • actions/upload-artifact main composite
  • r-lib/actions/check-r-package v1 composite
  • r-lib/actions/setup-pandoc v1 composite
  • r-lib/actions/setup-r v1 composite
  • r-lib/actions/setup-r-dependencies v1 composite
.github/workflows/pkgdown.yaml actions
  • actions/cache v1 composite
  • actions/checkout v2 composite
  • r-lib/actions/setup-pandoc v1 composite
  • r-lib/actions/setup-r master composite
tests/test_import/packageToTest/DESCRIPTION cran