community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.

R Tool not finding a function

Fireball

Has anyone ran into an issue where an r function did not work in Alteryx?  I'm using the dplyr function group_by_at which works just fine in RStudio, but for some reason, does not work here.   This is the code I'm  using:

 

# Load the packages
package_name <- c("dplyr", "segmented", "ggplot2", "stringr",
"broom", "tidyr", "tibble", "purrr")

altx.repo <- getOption("repos")
altx.repo["CRAN"] <- "https://cran.rstudio.com/"
options(repos = altx.repo)

lapply(package_name, library, character.only = TRUE)

# Read in the data from Alteryx into R
the_data <- read.Alteryx("#1", mode="data.frame")
the_data2 <- read.Alteryx("#2", mode = "data.frame")
the_data3 <- cbind(the_data, the_data2)

############################################################
#Get the exposure rates#
############################################################

vars <- names(the_data3)
exposure <- set_names(vars) %>%
map_df(function(var) {
var <- set_names(var, "level")
the_data3 %>%
group_by_at(var) %>%
summarize_at("eufactor", "sum") %>%
mutate_at("level", as.character)
}, .id = "variable")

write.Alteryx(exposure, 1)

 

Then I get a message that states could not find function "group_by_at" followed by an error.  Any ideas

Alteryx Certified Partner
Alteryx Certified Partner

While it didn't error when you loaded it, It sounds like the dplyr package isn't happy. Take careful note of version support when using R packages in Alteryx. This topic has a lot of good information about resolving version issues:

 

https://community.alteryx.com/t5/Data-Preparation-Blending/R-Tool-version-Error/td-p/6427

 

In a recent scenario, rather than resolving my own dplyr issues, I wrote a batch macro in R to loop on what would have been my group by field in the R tool.

Alteryx Certified Partner
Alteryx Certified Partner

It's worth noting that Alteryx has it's own R library from which it calls packages from, usually located at;

 

C:\Program Files\Alteryx\R-3.3.2\library

 

If something is working in RStudio and not R in Alteryx it's probably due to a missmatch in the packages that are available.

 

What I do in these instances is copy all the files from my Rstudio library into my Alteryx R library. Or of course you can specify the library path when calling the packages to point at the R studio library as by default it is pointing at the Alteryx one.

@CharlieS also raises some valid points.

Fireball

Thanks @BenMoss and @CharlieS.  I appreciate the replies. 

Labels