When an R package is not available in AML…

Posted By:

Being able to write R code on Azure Machine Learning (AML) is super useful for data analytics. AML has the capability of analyzing big data within a very short time. However, sometimes packages that are required for analysis are not available in AML. Entering “install.packages()” in the R script doesn’t support any function within the package. To solve this problem, there are two steps:

  • Download the package using local R Studio
  • Upload the package to AML

Here we are going to illustrate it step by step:

1 – Open your local R Studio

  • In the results, you may see more than one package are downloaded.
  • At the end, it will tell you where the package is in your local computer.
  • Install the package you need using the code “install.packages()”.

2 – Find the right folder according to above path.

  • Or you can search “downloaded_packages” in your computer. Select the right folder (highlighted by the blue line).

3 – Select all packages you just installed. In this example, there are 5 packages downloaded according to the previous R result.

4 – Right-click any of the selected folders, click “send to”, and then click “compressed (zip) folder”.

  • Rename the zip folder. In this example, we name it “forecast packages”.

5 – Move the zip folder to your desktop (or any other place that you can easily find).

6 – Open your browser and sign in your AML account.

  • Click “New”, choose “dataset”, and then choose “from local file”.

7 – Click “Browse” and select the package folder that you just zipped.

  • Click the checkmark at the right bottom.

8 – Once it’s uploaded as a dataset, find the package file in your dataset and drag it to the experiment.pic8

9 – Search “Execute R Script” in the searching area and then drag it to the experiment.

  • Connect the package to R script. Must connect to the most right dot which says “Script Bundle (Zip)”.

10 – Enter R code to install the package you need. Example codes:

install.packages(“./src/forecast_6.1.zip”, lib=”.”,repos=NULL, verbose=TRUE)

(Note: the package name should be the name of the sub folder under the zip file.)

library(forecast,lib.loc=”.”, verbose=TRUE)

11 – Click “Run” and then you can start to use any function within this R package.

You can upload any package from your local R Studio to AML. Once it’s done, you can write any functions supported by the package. In case you need more than one package to execute your R script, you can first download multiple packages in your local R Studio and then zip all of them into one zip folder before uploading to AML. This simple process allows for Azure Machine Learning to have the full extensibility and functionality of R.