MyNixOS website logo
Description

Simple Utility Providing Terminal Access to all R Functions.

A small utility which wraps Rscript and provides access to all R functions from the shell.

funr

Build Status cran license downloads

r fun(ction): attempt to make a fun cli for R

A small utility which wraps Rscript and provides easy access to all R functions from the terminal.

>funr

This aims to provide an easy command-line interface to all R functions.

Usage: funr [-h -v] <name of a function> <arguments to the function [<options>=<value>]>

funr -h            Show this help
funr -h <function> Show help for a specific function
funr -v            Show extra verbose messages for debugging this package
funr <func>        Find and run <function>
funr <func> [args] Run <func> with supplied [arguments]
funr <pkg::func>   Load the package <pkg>, and then run <func>

Examples:

Using a base package

## load help for rnorm
funr -h rnorm
    Normal                  package:stats                  R Documentation
    The Normal Distribution
    Description:
       Density, distribution function, quantile function and random

## sample 10 numbers from a normal distribution
funr rnorm n=10
    -1.244571 1.378112 0.02189023 -0.3723951 0.282709 -0.22854 -0.8476185 0.3222024 0.08937781 -0.4985827

Using a non-base packageLoading a package automatically by ::

## load help file for knitr
funr -h knitr::knit
    knit                   package:knitr                   R Documentation
    Knit a document
    Description:
       This function takes an input file, extracts the R code in it
       according to a list of patterns, evaluates the code and writes the
       output in another file. It can also tangle R source code from the

Knit a HTML file using a example R markdown input from knitr package:

## get path to an example Rmd file. Assuming we have knitr installed.
## Save the filename in a BASH variable rmd
## Pipes are supported starting version 0.1.2
funr system.file package=knitr fl=examples/knitr-minimal.Rmd | funr knitr::knit2html input=-
    loading pkg: knitr
    processing file: ... knitr/examples/knitr-minimal.Rmd
    output file: knitr-minimal.md
    knitr-minimal.html

Adding funr to your scripts

Create a file (called norm.r), which looks like the following:

#!/usr/bin/env Rscript

# define your functions
norm_hist <- function(n){
  x = rnorm(n)
  
  hist(x)
}

library(funr)
out = funr(commandArgs(trailingOnly = TRUE))

Make sure you have the shebang like with #!/usr/bin/env Rscript, so that shell knows that this is a Rscript. Also, add execution privilige to the script using:

chmod ugo+rx norm.r

Now, one may call the function:

norm.r norm_hist n=100

## OR
Rscript norm.r norm_hist n=100

Using devtools from terminal

Its it quite easy to customize the help text and load some default packages.

## download custom funr script
wget https://github.com/sahilseth/funr/raw/master/inst/scripts/devtools -O ~/bin/devtools

## installing a repo from github
devtools install_github repo="sahilseth/flowr"

## cd into a pacakge you want to check and run
devtools check .

## cd into a pacakge you want to build and run
devtools build .

Highlights:

  • Fetch all named parameters of the function and supply shell arguments after converting to the correct type
  • load help files, providing easy access to R man pages.
  • Automatically load any package and use any of its exported functions

Updates

This package is under active-development, you may watch for changes using the watch link above.

Installation:

automatically placed in your bin, and updated when the package gets updated

## a stable version
install.packages("funr")


## OR a latest developmental version
install.packages('devtools')
devtools::install_github("sahilseth/funr")

## setup
library(funr)
setup()
    A small script funr has been copied to ~/bin.
    Consider adding ~/bin to your PATH variable, by running this:
    echo 'export PATH=$PATH:~/bin' >> ~/.bashrc
    After opening a new shell session, running funr from the shell should work

To be able to run this utility without the need to use the full path, you need to add the folder containing the funr script to your PATH variable. The setup function copies a shortcut to this script to the ~/bin folder. Then you would need to add ~/bin to your PATH variable. You may do this using this command:

echo 'export PATH=$PATH:~/bin' >> ~/.bashrc

Alternatively, you may copy a shortcut to the funr script to any of the following folders on a linux/mac machine.

## Usually Unix based systems already contain these folders in the PATH variable:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin 

## Assuming /usr/local/bin is already in the path variable (check using echo $PATH),
## this might be a good place to install funr. 
## This would make it accesible to ALL users of the machine/server

## get path to the funr script
Rscript -e 'system.file("scripts/funr", package="funr")' ## get the path from this command:

## create a shortcut to the scruot
ln -s /Library/Frameworks/R.framework/Versions/3.2/Resources/library/funr/scripts/funr /usr/local/bin/
Metadata

Version

0.3.2

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • 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