Call "self" in R function as an argument -
i wondering if there elegant way of calling "self" in r function. easy illustration modification of date, let's date in int format (like when read excel).
a = 41557 = as.date(a, origin = "1899-12-30")
then "a" updated proper format. illustration simple, in context of long variable or more complicated procedure 1 utilize "self". exist in r. self meaning take variable @ left part of = sign.
a = 41557 = as.date(self, origin = "1899-12-30") # utilize self.
as first hint found out (i think) functions able phone call "self" somehow using "<-" operator example:
"minc<-" <- function(x, value){x*value}
gives :
a = 2 = minc(12) # = 24, : = self*12
i don't know if such keyword exist in r, helps in readability of of codes.
as always, help !
romain.
the functionality you're looking implemented in fantastic magrittr
package. version on cran introduces piping operator, %>%
, passes precedes first argument of follows (by default), or replaces .
preceding statement.
more point of question, version on github introduces many piping variants, including %<>%
works regular pipe, includes overwrite assignment.
the next statements equivalent (with magrittr
version >= 1.1.0, available on github, devtools::install_github("smbache/magrittr")
):
a = as.date(a, origin = "1899-12-30") = %>% as.date(origin = "1899-12-30") %<>% as.date(., origin = "1899-12-30") %<>% as.date(origin = "1899-12-30")
r function self
No comments:
Post a Comment