Search code examples
rpipevariable-assignment

could not find function "%<>%"


For some reason, R will recognize %>% (pipe operator) but not the %<>% (compound assignment pipe). The error I get is 'could not find function "%<>%"' - any ideas on how to fix this?


Solution

  • Load magrittr

    library(magrittr)
    x <- 4
    x %<>% sqrt
    x
    ## [1] 2
    

    Note that overwriting variables can make debugging more difficult.