MyNixOS website logo
Description

File Paths Relative to Project Roots.

Provides a set of helper functions for constructing file paths relative to the root of various types of projects, such as R packages, Git repositories, and more. File paths are specified with function arguments, or `$` to navigate into folders to specific files supported by auto-completion.

From where? fromhere!

Lifecycle:experimental CRANstatus R-CMD-check

The fromhere R package helps you create file paths relative to various project roots. It is inspired by the popular {here} package, but is more explicit about where exactly here() is.

The package supports many commonly used project types, allowing you to specify paths relative to various parts of your project. All path helpers prefixed with from_rproj(), allowing you to tab-complete the desired project root from one of these supported project roots:

  • from_wd(): For paths relative to the working directory.
  • from_here(): For paths relative to the {here} package’s automatic project root.
  • from_rproj(): For R project directories.
  • from_r_package(): For R package directories.
  • from_remake(): For remake project directories.
  • from_drake(): For drake project directories.
  • from_targets(): For targets project directories.
  • from_pkgdown(): For pkgdown project directories.
  • from_renv(): For renv project directories.
  • from_projectile(): For Projectile project directories.
  • from_quarto(): For Quarto project directories.
  • from_git(): For Git repository root directories.
  • from_svn(): For SVN repository root directories.
  • from_vcs(): For generic version control root directories (Git or SVN).
  • from_testthat(): For testthat directories.

Installation

To install the fromhere package from GitHub, use the remotes package:

# Install remotes if you don't have it yet
install.packages("remotes")

# Install fromhere from GitHub
remotes::install_github("mitchelloharawild/fromhere")

Usage

library(fromhere)

fromhere provides two main methods for generating file paths relative to the root of various project types:

  1. Using functions:from_rproj("path/to/file")

    Using strings to specify file paths, allowing a more programmatic approach to building paths.

  2. Using $ for autocompletion:from_rproj$path$to$file

    This method allows for a more interactive approach to specifying file paths, where the autocompletion is relative to the from_* folder.

Both methods produce the same result, and you should choose the method that best fits your needs.

File paths with functions

File paths can be specified using "strings" within the helper functions (much like here::here() and file.path()). You can use from_rproj("path/to/file") or pass multiple path components using from_rproj("path", "to", "file"). is more programmatic and provides flexibility for generating file paths.

The function will automatically generate the appropriate file path relative to the project root.

Examples:

  • From an R package:

    from_r_package("R", "from.R")
    #> [1] "/home/github/mitchelloharawild/fromhere/R/from.R"
    

    This generates the path to my_file.R in the R directory, relative to the root of the R package.

  • From a Git repository:

    from_git("vignettes/portable-paths.Rmd")
    #> [1] "/home/github/mitchelloharawild/fromhere/vignettes/portable-paths.Rmd"
    

    This generates the path to the portable-paths.Rmd vignette in the vignettes directory, relative to the root of the Git repository.

File paths with $

This method is ideal for interactive usage and provides autocompletion support for easier navigation. Once you call the from_rproj function, you can use the $ operator to navigate deeper into the directory structure, which is particularly useful when working interactively in RStudio or other IDEs.

Examples:

  • From an R package:

    from_r_package$R$from.R
    #> [1] "/home/github/mitchelloharawild/fromhere/R/from.R"
    

    This generates the path to my_file.R in the R directory, relative to the root of the R package.

  • For testthat tests:

    from_testthat$tests$testthat.R
    #> [1] "/home/github/mitchelloharawild/fromhere/tests/testthat.R"
    

    This generates the path to testthat.R in the tests directory, relative to the root of the testthat folder.

File paths created using this package can be further navigated with $, for example:

rpkg <- from_r_package()
rpkg
#> [1] "/home/github/mitchelloharawild/fromhere"
rpkg$R$from.R
#> [1] "/home/github/mitchelloharawild/fromhere/R/from.R"
Metadata

Version

0.1.0

License

Unknown

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows