wrapr 1.5.0 available on CRAN

June 13, 2018
By

(This article was first published on R – Win-Vector Blog, and kindly contributed to R-bloggers)

The R package wrapr 1.5.0 is now available on CRAN.

wrapr includes a lot of tools for writing better R code:

I’ll be writing articles on a number of the new capabilities. For now I just leave you with the nifty operator coalesce notation.

Coalesce takes values from its arguments in left to right order taking the first non-NA value (if any available):

NA %?% 5 
# [1] 5

1 %?% 5 
# [1] 1

5 %?% NA
# [1] 5

For vectors each position is calculated independently, and scalars are re-cycled to vector sizes. This allows fairly complicated coalesce strategies (such as take from first two vectors if possible, else write in zero) to be expressed very succinctly:

vec1 <- c(1, 2, NA, NA)
vec2 <- c(10, NA, 20, NA) 
vec1 %?% vec2 %?% 0
# [1]  1  2 20  0

To leave a comment for the author, please follow the link and comment on their blog: R – Win-Vector Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)