Start Free Trial

Alteryx Designer Desktop Discussions

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

R tool Error

ejtesoriero
6 - Meteoroid

Hi Team,

 

I am trying to run some R code using the R tool.  Every command I run results in the below error.  I have R 4.2.3 installed on my local machine and want to point the R tool in Alteryx to use my local machine's R library.  

 

"Error: R (2): Error: package or namespace load failed for 'stringr' in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]):"

 

I've tried running this command:
.libPaths( c( .libPaths(), "C:/Users/[USER ID]/AppData/Local/Programs/R/R-4.2.3/library") )

 

Any help would be appreciated!

Emily

2 REPLIES 2
Watermark
12 - Quasar
12 - Quasar

Do you have the predictive tools loaded for alteryx ?   It is loaded/added separately from designer itself. 

mjf
8 - Asteroid

Loading your machine's version of stringr is a really convoluted challenge.

 

An empty R tool loads a lot of packages. I have Alteryx 2022.1 and an empty R tool for me loads 70 packages, one of which is stringr. To load your local version, you need to unload the default version. To do this, add this line before you call your local stringr...

 

detach("package:stringr", unload = TRUE)
library("stringr", lib.loc = "/path/to/my/local/library")

 

The trouble is, if you run this then you'll find stringr cannot be unloaded because it is a dependency. So you'll have to run the above script, unloading/detaching package by package until you find the right combination for you to load your local version of stringr. I've have done this for another package, and I think I had to unload 15 packages before I could load my local package. It was a giant mess. 

 

Maybe if you use unloadNamespace() instead of detach()? I don't know if this'll work, though.

unloadNamespace("stringr")
library("stringr", lib.loc = "/path/to/my/local/library")

 

It is really easy to stumble upon package version conflicts between CRAN-based packages and Alteryx-based R packages, because Alteryx use a snapshot of the R packages they bundle with Predictive Tools, which is not updated like CRAN packages. If you manage to accomplish the right combination of unload/detach commands, then you are likely to find that your stringr is built on newer package versions than the rest of the packages bundled with Predictive Tools (rlang was particularly bothersome because it reverse depends 100s of packages). Alteryx need to host their own CRAN to solve this... I'd appreciate a like on my idea.

 

Updating the .libPaths() command is clever. You'll notice I've not done that, instead I have used the lib.loc argument in library(). This is because if the lib.loc argument is undefined, then the library() command looks through each location of the .libPaths() vector until it finds the package you've asked for. So, library() will find the normal Alteryx stringr in .libPaths()[1], .libPaths()[2], etc and load it - it will never look in your path because it is at the end of the .libPaths() vector. I'd recommend using lib.loc as I have done.

 

If you'd like to update .libPaths(), then reposition your new directory in the vector... like so

 

.libPaths( c( "C:/Users/[USER ID]/AppData/Local/Programs/R/R-4.2.3/library", .libPaths()) )

 

 

To see what packages are loaded in a empty R tool, use this

df <- data.frame(pkg = sessioninfo::session_info()$packages$package)
write.Alteryx(df, 1)

 

Hope this helps.

 

Labels
Top Solution Authors