Last active
July 21, 2021 13:45
-
-
Save danlooo/ea96fcda670348c22b05322e4a8b1ce7 to your computer and use it in GitHub Desktop.
Walrus Operator in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Assignment expression operator | |
#' | |
#' Creates an object with name `lhs` with the value `lhs` | |
#' and finally returns the value e.g. to pipe and print it | |
`%:=%` <- function(lhs, rhs, envir = parent.frame()) { | |
assign(deparse(substitute(lhs)), rhs, envir = envir) | |
rhs | |
} | |
# Create a varaible and print it's value | |
a %:=% 1337 %>% paste0("a=", .) | |
a | |
# Creates the plot object and actually plots it to the device | |
plt %:=% ggplot2::qplot(Sepal.Width, Sepal.Length, data = iris) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment