alteryx / alteryx/AlteryxRhelper

Add function to automatically create test workflows from R

Open
#6 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
R
Stars
20
Forks
2
PR merge metrics
No merged PRs in 30d

Description

``` r
#' Generate TextInput compatible XML for a Data Frame
df2TextInput <- function(x){
config <- read_xml("")
xml_add_child(config, "NumRows", value = as.character(NROW(x)))
fields <- xml_add_child(config, "Fields")
for (name in names(x)){
xml_add_child(fields, "Field", name = name)
}
data = xml_add_child(config, "Data")
for (i in 1:NROW(x)){
row = xml_add_child(data, "r")
for(j in 1:NCOL(x))
xml_add_child(row, "c", as.character(x[i,j]))
}
config
}

#' Generate Configuration XML from Configuration List.
config2xml <- function(props){
config <- read_xml("")
for (k in names(props)){
xml_add_child(config, "Value", name = k, paste(props[[k]], collapse = " + "))
}
config
}

#' Make workflow given data, template and tool ids.
makeWorkflow <- function(template, data, config, inputs_id, config_id, outFile){
getTool <- function(id){
sprintf("//Node[@ToolID = '%s']/Properties/Configuration", id)
}
doc <- read_xml(template)
n2 <- xml_find_first(doc, getTool(inputs_id))
textinput <- df2TextInput2(data)
invisible(xml_replace(n2, textinput))

n3 <- xml_find_first(doc, getTool(config_id))
xmlConfig <- list2xml(config)
invisible(xml_replace(n3, xmlConfig))
write_xml(doc, outFile)
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.