I have the following r code (snippet) in the r-tool and I trying to output it to my workflow.
doc <- htmlParse(temp) horse_name <- x <-xpathSApply(doc,"//tr[@bgcolor=\"white\"]/td[3]",xmlValue) horse_time <- x <-xpathSApply(doc,"//tr[@bgcolor=\"white\"]/td[4]",xmlValue) horse_dist <-xpathSApply(doc,"//tr[@bgcolor=\"white\"]/td[5]",xmlValue) horse_rail <-xpathSApply(doc,"//tr[@bgcolor=\"white\"]/td[6]",xmlValue) horse_avg <-xpathSApply(doc,"//tr[@bgcolor=\"white\"]/td[7]",xmlValue) horse_ahead <-xpathSApply(doc,"//tr[@bgcolor=\"white\"]/td[8]",xmlValue) horse_cu_time <-xpathSApply(doc,"//tr[@bgcolor=\"white\"]/td[11]",xmlValue) horse_cu_peak <-xpathSApply(doc,"//tr[@bgcolor=\"white\"]/td[12]",xmlValue) horse_cu_dist <-xpathSApply(doc,"//tr[@bgcolor=\"white\"]/td[13]",xmlValue) horse_cu_delta <-xpathSApply(doc,"//tr[@bgcolor=\"white\"]/td[14]",xmlValue) horse_cu_avg <-xpathSApply(doc,"//tr[@bgcolor=\"white\"]/td[15]",xmlValue) for(count in 1:length(horse_name)) { if(!is.null(horse_ahead[count]) && !is.na(horse_ahead[count])) { if(horse_ahead[count]!="Neck" && horse_ahead[count]!="Head" && horse_ahead[count]!="") { horse_ahead[count] <-str_replace(horse_ahead[count]," ","+") eval(parse(text=horse_ahead[count])) } } output <- cat(horse_name[count],horse_time[count],horse_dist[count],horse_rail[count],horse_avg[count],horse_ahead[count],horse_cu_time[count],horse_cu_peak[count],horse_cu_dist[count],horse_cu_delta[count],horse_cu_avg[count],'\n')
write.Alteryx(output, 1) } }
The last two lines of the code is where I'm trying to output my data to my workflow. However, I get an error message data parameter cannot be null, yet I don't think any null values are being produced. Can anyone share with me the best practice to output data from the R tool? Do I need to convert it to a data frame or perhaps a string? Thanks for your input.
Solved! Go to Solution.
A couple comments:
1. I would try to avoid the loop... can you "cbind" all the fields together?
2. If the loop can't be avoided, then I would initialize"output" as a data frame first, then add rows to it within the loop e g. with "rbind." Then afterward, write the entire data frame to the Alteryx output.
John,
Thanks for the reply. I had an opportunity to read up on rbind and I believe it will do the trick.
Thanks again.
Jim