@R_PACKAGE_NAME@-package: Get Script's Path

@R_PACKAGE_NAME@-packageR Documentation

Get Script's Path

Description

Determine the path of the executing script.

Compatible with several popular GUIs:

  • ‘Rgui’

  • ‘\RStudio’ (including background jobs)

  • ‘\Positron’

  • ‘\VSCode’ + ‘\REditorSupport’

  • ‘\Jupyter’

  • ‘\Emacs’ + ‘\ESS’

  • ‘\Rscriptlink’ (shell)

Compatible with several functions and packages: \syspathcompatiblelinks

Details

The most important functions from package:@R_PACKAGE_NAME@ are this.path(), this.dir(), here(), and this.proj():

  • this.path() returns the normalized path of the script in which it is written.

  • this.dir() returns the directory of this.path().

  • here() constructs file paths against this.dir().

  • this.proj() constructs file paths against the project root of this.dir().

New additions include:

  • LINENO() returns the line number of the executing expression.

  • shFILE() looks through the command line arguments, extracting FILE from either of the following: -f FILE or --file=FILE

  • set.sys.path() implements this.path() for any \sourcelink-like functions outside of the builtins.

  • with_init.file() allows this.path() and related to be used in a user profile.

package:@R_PACKAGE_NAME@ also provides functions for constructing and manipulating file paths:

  • path.join(), basename2(), and dirname2() are drop in replacements for \codelink3basefile.path(), \codelink3basebasename(), and \codelink3base:basenamedirname() which better handle drives and network shares.

  • splitext(), removeext(), ext(), and ext<-() split a path into root and extension, remove a file extension, get an extension, or set an extension for a file path.

  • path.split(), path.split.1(), and path.unsplit() split the path to a file into components.

  • relpath(), rel2here(), and rel2proj() turn absolute paths into relative paths.

Note

This package started from a stack overflow posting:

\Sexpr[results=rd,stage=install]{if (getRversion() >= "3.0.0") "\\\href{https://stackoverflow.com/questions/1815606/determine-path-of-the-executing-script/64129649#64129649}{https://stackoverflow.com/questions/1815606/determine-path-of-the-executing-script/64129649#64129649}" else "\\\ifelse{latex}{\\\href{https://stackoverflow.com/questions/1815606/determine-path-of-the-executing-script/64129649}{https://stackoverflow.com/questions/1815606/determine-path-of-the-executing-script/64129649}}{\\\href{https://stackoverflow.com/questions/1815606/determine-path-of-the-executing-script/64129649#64129649}{https://stackoverflow.com/questions/1815606/determine-path-of-the-executing-script/64129649#64129649}}"}

If you like this package, please consider upvoting my answer so that more people will see it! If you have an issue with this package, please use \codelink3utils:bug.reportbug.report(package = "@R_PACKAGE_NAME@") to report your issue.

Author(s)

@R_PACKAGE_AUTHOR@

Maintainer: @R_PACKAGE_MAINTAINER@


ArcadeAntics/this.path documentation built on July 27, 2024, 12:05 a.m.