How do I obtain the operator %<-%?

Reading the excellent tutorial by @jjallaire on time series forecasting with RNN (which is much better than most of the treatments of this topic I found on other blogs! The Tensorflow for R Blog has become one of my favorites), I found the following operator:

c(samples, targets) %<-% val_gen()

This is one of the few Python treats I really miss in R - the tuple unpacking (also known as multiple assignment). Do you know which package it comes from? The code snippet only imports keras, so it's surely there, but I wonder if it's defined in other packages too - it seems a bit pointless to import a DL library if I just want to use multiple assignment in a function which has nothing to do with DL. I had a look at keras dependencies, but according to the CRAN page it doesn't have any (only reverse dependencies/suggests).

It looks like it is re-exported from the zeallot package. See these lines in the rstudio/keras/R/reexports.R file:

#' Assign values to names
#'
#' See \code{\link[zeallot]{\%<-\%}} for more details.
#'
#' @name %<-%
#' @rdname multi-assign
#' @keywords internal
#' @export
#' @import zeallot
#' @usage x \%<-\% value
NULL

The zeallot package can be found here:

4 Likes

@tbradley is correct, but just wanted to clarify this point a bit. This is what keras CRAN page says:

Imports: reticulate (≥ 1.10), tensorflow (≥ 1.9), tfruns (≥ 1.0), magrittr, zeallot, methods, R6

So zeallot is indeed a dependency.

1 Like

Ah! The Imports line is on top of the page. I thought it was on the bottom, together with the lines on reverse dependencies. Thanks!

1 Like