Skip to contents

jamsession file paths

Usage

jamsession_paths(
  sessions = NULL,
  objects = NULL,
  functions = NULL,
  create = FALSE,
  mode = "0755",
  recursive = TRUE,
  verbose = FALSE,
  ...
)

Arguments

sessions, objects, functions

character vector with one or more file directory path locations, suitable for use by list.files(path=x). When a value is defined, it is used to override the existing options() value, so the updated value will be used for all related jamsession functions. Note that any value "" is removed, for example sessions="" is equivalent to sessions=NULL.

create

logical default FALSE, whether to create a file path that does not already exist. Only the first path is created for each of 'sessions', 'objects', 'functions' when none exist. The directory is created using dir.create() using the arguments mode and recursive.

mode, recursive

arguments passed to dir.create() when necessary, by the argument create.

verbose

logical indicating whether to print verbose output.

...

additional arguments are passed to dir.create().

Value

list with named elements 'sessions', 'objects', and 'functions'.

Details

This function retrieves the file path for each jamsession type:

  1. 'sessions': the folder where R sessions are saved, stored in getOption("jam.sessions_path"), default "~/Projects/R-sessions".

  2. 'objects': the folder where R objects are saved, stored in getOption("jam.objects_path"), default "~/Projects/R-objects".

  3. 'functions': the folder where R functions are saved, stored in getOption("jam.functions_path"), default "~/Projects/R-scripts".

Each may have multiple paths, and may contain "." to include the current working directory.

To use persistent values for your R environment, define options() in the ~/.Rprofile in your HOME directory, or in the folder of the active project.

To use custom file paths in each R session, use either ~/.Rprofile or an appropriate method to define the relevant options.

  • options("jam.sessions_path"="/some/path/sessions"),

  • options("jam.objects_path"="/some/path/objects"),

  • options("jam.functions_path"="/some/path/functions").

Examples

## Display the current or default paths
c(jamsession_paths(functions=NULL))
#> $sessions
#> [1] "~/Projects/R-sessions"
#> 
#> $objects
#> [1] "~/Projects/R-objects"
#> 
#> $functions
#> [1] "~/Projects/R-scripts"
#> 

## Update the functions path
jamsession_paths(functions="~/Projects/R-functions")
#> $sessions
#> [1] "~/Projects/R-sessions"
#> 
#> $objects
#> [1] "~/Projects/R-objects"
#> 
#> $functions
#> [1] "~/Projects/R-functions"
#> 

## confirm the functions path has been updated
c(jamsession_paths())
#> $sessions
#> [1] "~/Projects/R-sessions"
#> 
#> $objects
#> [1] "~/Projects/R-objects"
#> 
#> $functions
#> [1] "~/Projects/R-functions"
#> 
getOption("jam.functions_path")
#> [1] "~/Projects/R-functions"

## Revert the functions path
c(jamsession_paths(functions="~/Projects/R-scripts"))
#> $sessions
#> [1] "~/Projects/R-sessions"
#> 
#> $objects
#> [1] "~/Projects/R-objects"
#> 
#> $functions
#> [1] "~/Projects/R-scripts"
#>