Syntactic sugar for R
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
R
man
DESCRIPTION
NAMESPACE
README.org

README.org

sugar

Some syntactic sugar for R.

Appending objects to lists

Assume we have an list and some objects we want to be named parts of this list.

mylist <- list()
numbers <- 1:20
breakfast <- "chunky bacon"
wood <- list(oak = "hard", spruce = "soft")

In R, you usually do

mylist$numbers <- numbers

to append a single object to this list. The same thing has to be done for multiple objects:

mylist$breakfast <- breakfast
mylist$wood <- wood

The sugar provided shortens this to:

mylist %$% numbers

for the case of appending a single object, and for multiple objects to:

mylist %$% c(breakfast, wood)

This is achieved using global assignment, so be careful when using this non-interactively.

Loading multiple packages with one call

Instead of

library(utils)
library(mgcv)
library(sp)

We can do

libraries(utils, mgcv, sp)