Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

Installing a new R package that's compatible with YOUR version of Alteryx Designer

mjf
8 - Asteroid

Hello there

 

There is a recurring theme when it comes to installing R packages with Alteryx and it's my hope that this post resolves the situation for you.

 

The Problem

Running install.packages() in Alteryx, without directing it to the right location, will install the latest version of that package. The latest version of R on CRAN is R 4.2.2, so it is unlikely that the package that will be installed is compatible with the Alteryx that you run. I currently use Alteryx Designer 2022.1.1.40869, patch 2, which uses R 4.1.3. What we need to do is tell install.packages() to look for your package in the right place.

 

A Solution

As Alteryx is based on Windows (#alteryx4linux), we need the binaries associated with the package. Take a look at this webpage https://cran.r-project.org/bin/windows/contrib and you will find the location of pre-built Windows binaries for all the packages available for R => 3.4.x.

 

So, now that we've found the parent directory, which one do we pick? Good question. Let's use R to help us decide.

 

library(dplyr)
library(tidyr)
library(stringr)

# contriburl R 4.0 packages
r40 <- readLines(con = "https://cran.r-project.org/bin/windows/contrib/4.0/PACKAGES")
pkgname <- str_remove(r40[grep("Package:", r40)], "Package: ")
pkgver <- str_remove(r40[grep("Version:", r40)], "Version: ")
r40df <- data.frame(pkg = pkgname, r40v = pkgver)

# contriburl R 4.1 packages
r41 <- readLines(con = "https://cran.r-project.org/bin/windows/contrib/4.1/PACKAGES")
pkgname <- str_remove(r41[grep("Package:", r41)], "Package: ")
pkgver <- str_remove(r41[grep("Version:", r41)], "Version: ")
r41df <- data.frame(pkg = pkgname, r41v = pkgver)

# "base" Alteryx packages
altdf <- as.data.frame(installed.packages(lib.loc = .libPaths()[1]))
altdf <- data.frame(pkg = altdf$Package, altv = altdf$Version)

# create final data frame
temp <- merge(r40df, r41df, all = TRUE)
df <- merge(temp, altdf, all = TRUE) %>% drop_na()

 

The above code creates a table of all the R packages bundled with my Alteryx with the version numbers for each one. It also contains a column of version numbers of the packages contained in the 4.0 and 4.1 directories. Direct the lib.loc argument to where R is installed (for me this is C:/Program Files/Alteryx/R-4.1.3/library), run the script and inspect the data frame. What you will likely see is that some versions in Alteryx are the same as those in 4.0, whilst others are the same in 4.1. It is a mixed bag! When you install a new package, you need to decide which location to grab it from; there will be some trial and error with this.

 

This is what I use

 

install.packages(<pkg>, lib = .libPaths()[4], contriburl = "https://cran.r-project.org/bin/windows/contrib/4.0", dependencies = TRUE)

 

For my employer's setup, .libPaths()[4] is what I need because I do not have write access to the other directories in the .libPaths() character vector; you may wish to specify another location. The contriburl argument is the location of all the packages in the version you choose (4.0 for me). With this command, install.packages() looks for the PACKAGES file on this webpage for information about the packages available (see the readLines() con argument above), including the suggests/imports/etc. and installs what you request according to the dependencies argument.

 

Just like a MS Windows installation, an empty R Tool automatically loads many packages - bloatware! If you want to install a new package that has a dependency, which is newer version than the one the R Tool loads, then you need to detach the package before you install the newer dependency. This can be very convoluted. For example, the caret package from 4.1 depends on rlang => 1.03, but the R Tool loads rlang 1.02. This is what I did to remove rlang 1.02 from the R Tool before the newer rlang was installed.

 

unloadNamespace("dplyr")
unloadNamespace("tidyselect")
unloadNamespace("purrr")
unloadNamespace("AlteryxPredictive")
unloadNamespace("ggplot2")
unloadNamespace("tibble")
unloadNamespace("pillar")
unloadNamespace("vctrs")
unloadNamespace("ellipsis")
unloadNamespace("scales")
unloadNamespace("lifecycle")
unloadNamespace("flightdeck")
unloadNamespace("DT")
unloadNamespace("htmlwidgets")
unloadNamespace("htmltools")
unloadNamespace("rlang")

 

What a mess! It was far easier for me to install the caret from 4.0, which depends on the rlang bundled with Alteryx. This is a good example of why you need to determine which contriburl argument is right for your needs!

 

Final thoughts

R development is continual and dynamic, whereas the version of R compatible with Alteryx is not... well, you are free to update R in whatever way you'd like, but you run the risk of it not working with Alteryx! To get the right package, you need to get the right version for the Alteryx you have. Use the contriburl argument with install.packages() to find the right version for your needs!

 

I hope this helps!

 

8 REPLIES 8
AndrewSu
Alteryx
Alteryx

@mjf , this is some great content and insight!

 

Please mark this reply as the solution so that we can clean up the posts in community and make it easier for others to benefit from your great work. 

 

Thanks. 

 

 

mjf
8 - Asteroid

Hello again

 

I have had some further thoughts on the subject.

 

Binaries vs Source

The install.packages() function defaults the type argument to one that installs prebuilt binaries for Windows users. If you'd like to install from source then you need to have Rtools installed (not to be confused with the Alteryx 'R Tool'), which can be found here. Please note that the latest version of Rtools is not compatible with the version of R used in the latest version Alteryx. For Alteryx use, you need Rtools 4.0 installed, not 4.2.

 

To be honest, I don't know the pros and cons between downloading binaries or installing from source with Rtools. All I know is that I and my colleagues have faced mismatching DLLs with the pre-built binaries and it is my hope that Rtools will solve this. It's about to arrive on my work machine and I hope the DLL issue will be resolved soon; my work's IT dept have their own installation policies so I haven't got Rtools yet.

 

Further final thoughts

As I said in my first post, it is a mixed bag, so tread with care. You may find it best to use install.packages() with dependencies set to FALSE, thereby forcing your downloaded package to use the dependency that is loaded by the R Tool in the first instance. If that doesn't work for you, then use unloadNamespace() and/or detach() and run install.packages() again with dependencies set to TRUE. You will notice that, without any other arguments, install.packages() automatically downloads the requested package from the latest contriburl (read the messages as your package is downloaded).

 

I'm more of a R user working with Alteryx, rather than the other way round. If you need help with R then please check out stackoverflow for community-driven posts or the R Documentation website. I find it best to develop R in RStudio, which I direct to the Alteryx version of R in Tools > Global Options, then copy and paste to the R Tool in Alteryx. At that point I introduce the R Tool-specific R code. I find it helps to see all the warnings, errors, debugging tools, etc. without needing to run a workflow. I'd encourage you all to work with RStudio (or any other comparable IDE) before you bring your code into the R Tool.

 

My advice to anybody working with code written by another, like Macros, is this: remove every line related to installing packages and install them yourself. This is because there is a good chance that the macro worked when it was developed but won't work now without some changes.

 

Good luck!

mjf
8 - Asteroid

Here is some useful code to determine the Depends, Imports, Suggests, etc of a given package in a contriburl:

m <- available.packages(contriburl = "https://cran.r-project.org/bin/windows/contrib/4.0")
m["lime", "Suggests"]

 The available.packages() command outputs a matrix with row names as package names.

 

R development vs Alteryx-specific R development

The R Project will release a new version of base R and, in conjunction with package authors, begin the long process of compiling updated packages for use with the new base R. There are nearly 20,000 packages... a lot of package authors... and the process can take many months. At some point, Alteryx used the base R 4.1.3 and the packages available at that time to develop their Alteryx-specific packages; this approach is fine. The trouble is that package authors continue to supply their code for compilation and it results in packages that are newer versions than the ones used when Alteryx created their Alteryx-specific packages.

 

A helpful thing that Alteryx can do is state the date R was pulled from CRAN for their development in each 'help' webpage for R-related tools and the webpage for Predictive Tools.

 

The most helpful thing Alteryx can do is to have regular updates for Predictive Tools in line with package changes on CRAN. Checking package updates to the CRAN repository for the packages the Predictive Tools depend upon can be a simple thing to automate, recoding to account for the CRAN package updates is another matter.

 

I hope this is something Alteryx can do for us!

mjf
8 - Asteroid

I have created a new Idea that ought to solve a lot of the problems addressed in my post. My idea is for Alteryx to host their own CRAN!

Alteryx hosting CRAN - Alteryx Community

fmvizcaino
17 - Castor
17 - Castor

Amazing content, @mjf !!!

mjf
8 - Asteroid

I've discovered some more useful code since I first posted about the subject.

 

The aim of this code is to install the version of a package that was available at the time Alteryx Predictive Tools was built. To find out when it was built we need to read the DESCRIPTION file, to do this run the following

 

 

installed.packages() # lists all installed packages, find Alteryx-specific packages here
packageDescription("AlteryxPredictive") # displays the package DESCRIPTION file

 

 

Use this command on AlteryxPredictive and the other Alteryx-specific packages to find a date to work from. Then look here for an archive of packages. Open the link to the package you want and, armed with the build date from the code above, download the zip file containing the version that was available when Alteryx Predictive was built. Use install.packages() to install from source.

 

 

install.packages("path/to/downloaded/file", type = "source", dependencies = FALSE)

 

 

You may need to play around with the dependencies a bit, but I suggest beginning with FALSE and see how you get on. Then use library() to attach the package you've just installed.

 

library(<pkg_name>, lib.loc = "path/to/where/Rtools/installed/your/package")

 

mscuaycong
7 - Meteor

Thank you, mjf.  I was pulling my hair trying to match up the package versions and couldn't make things work.  Like you said when you load the R tool - it's already bloated to begin with.  

Needless to say, your post helped me out tremendously and i was able to install Caret with the dependencies in the correct order and now it WORKS!

 

Thanks much.

mjf
8 - Asteroid

You are very welcome. Some of the information in the earliest posts is wrong, I am always learning something new myself, so I am glad some of it worked for you. Out of interest, are you using Caret for the Lime macro? If so, I have added a post that may have helped you. Expand Your Predictive Palette V: No More Black Bo... - Alteryx Community

 

I would be very grateful if you can like my Idea for Alteryx to host their own CRAN, as this is the easiest way for Alteryx to make life easier for us R users.

 

Thank you.

Labels