R bloggers

Supercharge your R code with wrapr

FavoriteLoadingAdd to favorites

I would like to demonstrate some helpful wrapr R notation tools that really neaten up your R code. Img: Christopher Ziemnowicz. Named Map Builder First I will demonstrate wrapr‘s “named map builder”: :=. The named map builder adds names to vectors and lists by nice “names on the left and values on the right” notation. For example to build a named vector mapping names c(“a”, “b”) to values c(1, 2) we could write the following R code. c(a = 1, b = 2) ## a b ## 1 2 Or we can write: c(“a” = 1, “b” = 2) ## a b ## 1 2 Using wrapr we can write the same thing for quoted names using :=. library(“data.table”) # data.table before wrapr to avoid := contention suppressPackageStartupMessages(library(“dplyr”)) library(“wrapr”) ## ## Attaching package: ‘wrapr’ ## The following object is masked…
Original Post: Supercharge your R code with wrapr