https://github.com/astrazeneca/qsuse

R library that provides an import mechanism like python to import local source files. It is not meant to replace library(), or doublecolon:: prefixing

https://github.com/astrazeneca/qsuse

Science Score: 13.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
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.1%) to scientific vocabulary
Last synced: 9 months ago · JSON representation

Repository

R library that provides an import mechanism like python to import local source files. It is not meant to replace library(), or doublecolon:: prefixing

Basic Info
  • Host: GitHub
  • Owner: AstraZeneca
  • Language: R
  • Default Branch: master
  • Size: 13.7 KB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • Open Issues: 0
  • Releases: 0
Created about 2 years ago · Last pushed about 2 years ago
Metadata Files
Readme

README.md

qsuse

R library that provides an import mechanism like python to import local source files. It is not meant to replace library(), or doublecolon:: prefixing. It is meant to guarantee that a large codebase can achieve the following goals:

  • explicitly describe what a given .R file actually needs, by moving the import process from the main file to each individual subfile.
  • import symbols (functions, global variables) into separate environments so that there is no risk of collision between symbols with the same name in two R files of the same project.
  • manage already imported modules so that no double execution occurs.

Usage

Imagine you have files organised as follows: basedir/module.R basedir/module2.R basedir/module2/hello.R basedir/module3/submodule/whatever.R basedir/app.R

You use qsuse in e.g. app.R by first defining the search path

prepend_search_path("/path/to/basedir")

You can get this path via various methods, e.g. with here::here()

Then, you can import module as

module <- qsuse::use("module")

Functions and variables that are defined in module will be accessible as

module$myfunc()

Nothing forces you to use the same name for the variable. This is allowed:

mod <- qsuse::use("module") mod$myfunc()

You can also import a specific function with useonly()

myfunc <- qsuse::use("module", "myfunc")

If a module is too long, you can shorten it by using prefixes

submodule <- qsuse::prefix("module3/submodule") whatever <- qsuse::use(submodule("whatever"))

Note that if you have a directory and a file named exactly as that directory, the content of the files will be imported too. For example,

```

Imports the contents of module2.R

module2 <- qsuse::use("module2")

Imports the content of hello.R (under the hood, also imports module2.R but you are not

seeing that module here)

hello <- qsuse::use("module2/hello") ```

Each of the returned variables are separated environments. This namespaces each file and prevents accidental collisions.

Why not box?

Box does not perform static symbol binding. The result is that lintr cannot detect the added symbols during static analysis. We also have more control of what kind of environment is returned.

Owner

  • Name: AstraZeneca
  • Login: AstraZeneca
  • Kind: organization
  • Location: Global

Data and AI: Unlocking new science insights

GitHub Events

Total
  • Fork event: 1
Last Year
  • Fork event: 1

Committers

Last synced: 11 months ago

All Time
  • Total Commits: 1
  • Total Committers: 1
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Stefano Borini s****i@a****m 1
Committer Domains (Top 20 + Academic)

Dependencies

DESCRIPTION cran