Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Stuck trying to write a dataframe to a workflow from the R tool

pimp_fada
7 - Meteor

Hi, I am currently stuck trying to write output from my R script with the R tool. Here's the R code: 

 

# Needed Packages
library(prophet)
library(dplyr)

# Read data
df1  <- read.Alteryx("#1",mode="data.frame")


# Subset The Relevant fields
df <- df1 %>% select("ds", "datasource_id", "y")

# A 5 Year Forecasting Model
df2 <- df %>% 
  group_by(datasource_id) %>% 
  do(predict(prophet(., interval.width = 0.95), 
             make_future_dataframe(prophet(., interval.width = 0.95),
                                   periods = 12*5, freq = "month"))) %>% 
  select(ds, datasource_id, yhat)

final_df <- as.data.frame(df2, row.names = NULL)

# Write final forecasting Output Back To The Workflow
write.Alteryx(final_df, 1)

I get this error when the code tries to write back to the flow: 

Error: R (178): There was an error in WriteYXDBStreaming 

The code itself seems to be running just fine. It's just getting R and Alteryx to see eye to eye when it comes to writing the final output which seems to be an issue. 

 

Here's the head of the final_df dataset which I'm trying to write in alteryx.

 

            ds datasource_id     yhat
1   2016-01-01           153 7.800964
2   2016-02-01           153 8.175739
3   2016-03-01           153 8.369714
4   2016-04-01           153 8.735363
5   2016-05-01           153 8.689885

 

Any way around this? 

2 REPLIES 2
pimp_fada
7 - Meteor

It seems the error is from the 'ds' field which is a datetime object in tibble. For some reason Alteryx hates this format so I had to convert it into a date object with this snippet: 

 

final_df <- df2 %>% 
  select(ds, datasource_id, yhat) %>%
  mutate(ds_1 = as.Date(ds)) %>% 
  select(-(ds)) %>% 
  rename(ds = ds_1)

# Convert tibble to dataframe
final_df <- as.data.frame(final_df)

 

Alteryx finally is able to write this dataframe back to the workflow

TimothyL
Alteryx Alumni (Retired)

@pimp_fada 

 

Recently, we have developed a Prophet Tool in R for more drag & drop features. Hope the R code can be a good reference to you

https://community.alteryx.com/t5/Data-Science-Blog/Expand-Your-Predictive-Palette-III-I-Sales-Foreca...

 

TL

Labels