Alternative functions to make R scripting even easier and more user-friendly. For instance, it includes the library0() function which is a library function replacement to install (if needed) and load libraries in one step; and also including GitHub packages installation compatibility. There are other alternatives, such as cat0, catn or stop0 in other to modify the behaviour of both cat and stop functions respectively.
This is an alternative function to library, which pretends to be an easier way to attach and install a package in the same step and it also installs the package if needed. It is also compatible with GitHub packages without using additional libraries.
You can indicate the package as a string or directly by the name. It also works with GitHub packages through the install-github.me service, which is based on remotes
# Load and install (if so) CRAN and GitHub R packages, and automatically as character strings or not
library0("ggplot2")
library0(ggplot2)
library0(hadley/devtools)
cat0
is an alternative to cat, as paste0
for paste
, without spaces.
cat0('string', 'withoutspaces')
cat0
is an alternative to cat but including a newline by default.
catn('string', 'withoutspaces', 'andanewline')
This is indeed the same as stop but quietly, very useful when included in the middle of a source file and you want to stop it without a warning message.
stop0()
It returns the last element of an array or dataframe.
last(c(1,2,3))
There are several options, my favourite one is just as follows:
source('https://install-github.me/ahornero/alternatives')
Another, and also more popular way to install it:
library(devtools)
install_github('ahornero/alternatives')
One more!
library(githubinstall)
githubinstall('alternatives')