Pasta: Noodlyfied Pasting of Strings"

Introduction (Antipasto)

Base R provides a functionality to concatenate strings through the paste functions. Using paste is nice and dandy, but the code can get quite difficult to read. Especially if two paste functions need to be nested.

Pasta provides a set of infix functions to make concatenation noodlier. This can make the code more intuitive and readable.

Examples (Primo Piatto)

Here are some tasty examples of the provided functionality:

  require(pasta, quietly = TRUE)
  #
  examples <- c(
  'macaroni' %_% 'sauce',
  'ravioli' %-% 'recipe',
  'spaghetti' %.% 'code',
  'fussili' %//% 'farfalle',
  'pasta' %&% 'sciutta',
  'noodle' %&&% 'soup',
  'carbonara' %|% 'ragout',
  'spaghetti' %&&% 'al' %-% 'dente'
  )
  print(examples)

As a less naive example let us assume that we want to create a fancy animation with some screen-caps of our favorite spaghetti-western. Here is some pasta code that shows how we can download a set of chosen pictures from one of the many nice sites that provide the captures:

  cap_url <- "http://www.caps.media/195/9-rio-bravo/full/rio-bravo-movie-screencaps.com"
  jpg_urls <- cap_url %-% c(4,5,264:268) %.% "jpg"
  for (i in 1:length(jpg_urls)) {
      download.file(jpg_urls[i], c("rio_bravo" %_% i %.% "jpg"), mode = "wb")
  }


Try the pasta package in your browser

Any scripts or data that you put into this service are public.

pasta documentation built on May 29, 2017, 10:51 p.m.