I read many articles about R
promises
(including this) and still don't get it.
See code:
library(future)
library(promises)
plan(multiprocess)
read.csv.async <- function(file, header = TRUE, stringsAsFactors = FALSE) {
future({
read.csv(file, header = header, stringsAsFactors = stringsAsFactors)
})
}
df_promise <- read.csv.async("https://rstudio.github.io/promises/data.csv")
df_promise %...>% filter(state == "NY")
df_filtered_promise <- df_promise %...>% filter(state == "NY")
df_filtered_promise
class(df_filtered_promise)
Output:
> read.csv.async <- function(file, header = TRUE, stringsAsFactors = FALSE) {
+ future({
+ read.csv(file, header = header, stringsAsFactors = stringsAsFactors)
+ })
+ }
>
> df_promise <- read.csv.async("https://rstudio.github.io/promises/data.csv")
>
> df_promise %...>% filter(state == "NY")
>
> df_filtered_promise <- df_promise %...>% filter(state == "NY")
>
> df_filtered_promise
<Promise [pending]>
> df_filtered_promise
<Promise [fulfilled: data.frame]>
> class(df_filtered_promise)
[1] "promise"
Why fullfilled promise
doesn't return its value? How can I extract data frame in my case?
future
works, butpromises
. – Invarlibrary(promises)
– Invardf_promise %...>% print()
and it will print it out, but I don't want it printed, I want it realized/gathered. I wonder if the intent forpromises
is really not at all user-interactive so much asshiny
(for which it works well). – Extern