Read R output as is
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi,
If I have the following code, for example
shapiroNormality <- shapiro.test(data$var1) write.Alteryx(shapiroNormality, 1)
and I use a Browse tool to read the output, I get the results in a table.
Is there a way to read R output as is?
Thanks.
Solved! Go to Solution.
- Labels:
- R Tool
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I'm curious what you were looking for other than the values in the table. I ran a shapiro.test and the output from it is the same as the table (data frame, or vector) that we see in Alteryx.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Yes John. My question is actually about the format not the content. Can I read R's output as if it was written to the console?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Based on the documentation here https://stat.ethz.ch/R-manual/R-devel/library/stats/html/shapiro.test.html, the output of the shapiro.test function is a list with elements 'statistic', 'pvalue', 'method', and 'dataname'. Alteryx's only way to read this in stream is as a dataframe type of object. So there's no super nice way to see the R output exactly as it pops up in your RStudio console. You can use the print method in R and look in the messages in Alteryx; I think that's the closest you can probably get.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
This is failing
wilcoxPoints <- wilcox.test(data_all$points~data_all$source, data=data_all) write.Alteryx(wilcoxPoints, 1)
R (16) Error in data.frame(statistic = 570563.5, parameter = NULL, p.value = 0.646636541214278, :
R (16) arguments imply differing number of rows: 1, 0
R (16) Calls: write.Alteryx ... as.data.frame -> as.data.frame.list -> eval -> eval -> data.frame
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@nabegh, I believe you can use capture.output in order to gather output from R to a variable, but you still need to massage it a little.
Fortunately Alteryx is great at massaging data: I've attached a workflow that supplies the output as seen on the console as 4 rows of character data. Hope that helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Okay. It looks like the error you are getting is stemming from the fact that R is providing a list which is being coerced into a dataframe for Alteryx to use, and it is converting param = NULL into an empty list instead of param = c(NULL).
Here's what I came up with (obviously, change the value of w to be the result of the wilcox test):
w <- wilcox.test(rnorm(100, mean = 5, sd = 3)) convertForAlteryx <- function(name) { if(is.null(w[[name]])) { c(NA*1) } else { w[[name]] } } wdf <- as.data.frame(lapply(names(w), FUN = convertForAlteryx))
names(wdf) <- names(w) write.Alteryx(wdf)
Or if you prefer this vertically,
w <- wilcox.test(rnorm(100, mean = 5, sd = 3)) convertForAlteryx <- function(name) { if(is.null(w[[name]])) { NA*1 } else { w[[name]] } } ids <- names(w) vals <- unlist(lapply(names(w), FUN = convertForAlteryx)) wdf <- data.frame(ids, vals) write.Alteryx(wdf)
