4.3 OML User Tasks for Downloading and Using an Available Conda Environment

Once user ADMIN installs the environment in Object Storage, as an OML user, you can download, activate, and use it in R paragraphs in notebooks and with embedded execution.

List all environments persisted in Object Storage

Get the list of environments saved in Object Storage using the list-saved-envs command.

%conda

list-saved-envs 

Get information on a named environment persisted in Object Storage

Provide the environment name as an argument to the -e parameter and request information on the environment.

%conda

list-saved-envs -e myrenv

The output is similar to the following:

{
  "name": "myrenv",
  "size": "831.5 MiB",
  "description": "Install R forecast and ggplot2 packages",
  "tags": {
    "application": "OML4R",
    "user": "OMLUSER"
  },
  "number_of_installed_packages": 121
}

Download and activate the environment

Use the download command to download an environment from Object Storage. To activate the downloaded environment, use the activate command.

Note:

The paragraph that contains the download command must be the first paragraph in the notebook.
%conda

download myrenv
activate myrenv
Downloading conda environment myrenv
Download successful for conda environment myrenv

List the packages available in the environment

Get the list of all the packages in an active environment using the list command.

%conda

list

The output is similar to the following:

# packages in environment at /u01/.conda/envs/myrenv:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
_r-mutex                  1.0.1               anacondar_1    conda-forge
binutils_impl_linux-64    2.39                 h6ceecb4_0    conda-forge
bwidget                   1.9.14               ha770c72_1    conda-forge
bzip2                     1.0.8                h7f98852_4    conda-forge
c-ares                    1.18.1               h7f98852_0    conda-forge
ca-certificates           2022.9.24            ha878542_0    conda-forge
cairo                     1.16.0            ha61ee94_1014    conda-forge
curl                      7.86.0               h2283fc2_1    conda-forge
expat                     2.5.0                h27087fc_0    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 hab24e00_0    conda-forge
fontconfig                2.14.1               hc2a2eb6_0    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
freetype                  2.12.1               hca18f0e_0    conda-forge
fribidi                   1.0.10               h36c2ea0_0    conda-forge
gcc_impl_linux-64         12.2.0              hcc96c02_19    conda-forge
gettext                   0.21.1               h27087fc_0    conda-forge
gfortran_impl_linux-64    12.2.0              h55be85b_19    conda-forge
graphite2                 1.3.13            h58526e2_1001    conda-forge
gsl                       2.7                  he838d99_0    conda-forge
gxx_impl_linux-64         12.2.0              hcc96c02_19    conda-forge
harfbuzz                  5.3.0                h418a68e_0    conda-forge
icu                       70.1                 h27087fc_0    conda-forge
jpeg                      9e                   h166bdaf_2    conda-forge
kernel-headers_linux-64   2.6.32              he073ed8_15    conda-forge
keyutils                  1.6.1                h166bdaf_0    conda-forge
krb5                      1.19.3               h08a2579_0    conda-forge
ld_impl_linux-64          2.39                 hc81fddc_0    conda-forge
lerc                      4.0.0                h27087fc_0    conda-forge
libblas                   3.9.0           16_linux64_openblas    conda-forge
libcblas                  3.9.0           16_linux64_openblas    conda-forge
libcurl                   7.86.0               h2283fc2_1    conda-forge
libdeflate                1.14                 h166bdaf_0    conda-forge
libedit                   3.1.20191231         he28a2e2_2    conda-forge
libev                     4.33                 h516909a_1    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-devel_linux-64     12.2.0              h3b97bd3_19    conda-forge
libgcc-ng                 12.2.0              h65d4601_19    conda-forge
libgfortran-ng            12.2.0              h69a702a_19    conda-forge
libgfortran5              12.2.0              h337968e_19    conda-forge
libglib                   2.74.1               h7a41b64_0    conda-forge
libgomp                   12.2.0              h65d4601_19    conda-forge
libiconv                  1.17                 h166bdaf_0    conda-forge
liblapack                 3.9.0           16_linux64_openblas    conda-forge
libnghttp2                1.47.0               hff17c54_1    conda-forge
libopenblas               0.3.21          pthreads_h78a6416_3    conda-forge
libpng                    1.6.38               h753d276_0    conda-forge
libsanitizer              12.2.0              h46fd767_19    conda-forge
libssh2                   1.10.0               hf14f497_3    conda-forge
libstdcxx-devel_linux-64  12.2.0              h3b97bd3_19    conda-forge
libstdcxx-ng              12.2.0              h46fd767_19    conda-forge
libtiff                   4.4.0                h55922b4_4    conda-forge
libuuid                   2.32.1            h7f98852_1000    conda-forge
libwebp-base              1.2.4                h166bdaf_0    conda-forge
libxcb                    1.13              h7f98852_1004    conda-forge
libxml2                   2.10.3               h7463322_0    conda-forge
libzlib                   1.2.13               h166bdaf_4    conda-forge
make                      4.3                  hd18ef5c_1    conda-forge
ncurses                   6.3                  h27087fc_1    conda-forge
openssl                   3.0.7                h166bdaf_0    conda-forge
pango                     1.50.11              h382ae3d_0    conda-forge
pcre2                     10.37                hc3806b6_1    conda-forge
pixman                    0.40.0               h36c2ea0_0    conda-forge
pthread-stubs             0.4               h36c2ea0_1001    conda-forge
r-backports               1.4.1             r41h06615bd_1    conda-forge
r-base                    4.1.3                h7880091_3    conda-forge
r-brio                    1.1.3             r41h06615bd_1    conda-forge
r-callr                   3.7.3             r41hc72bb7e_0    conda-forge
r-cli                     3.4.1             r41h7525677_1    conda-forge
r-colorspace              2.0_3             r41h06615bd_1    conda-forge
r-crayon                  1.5.2             r41hc72bb7e_1    conda-forge
r-curl                    4.3.3             r41h06615bd_1    conda-forge
r-desc                    1.4.2             r41hc72bb7e_1    conda-forge
r-diffobj                 0.3.5             r41h06615bd_1    conda-forge
r-digest                  0.6.30            r41h7525677_0    conda-forge
r-ellipsis                0.3.2             r41h06615bd_1    conda-forge
r-evaluate                0.18              r41hc72bb7e_0    conda-forge
r-fansi                   1.0.3             r41h06615bd_1    conda-forge
r-farver                  2.1.1             r41h7525677_1    conda-forge
r-forecast                8.18              r41h37cf8d7_0    conda-forge
r-fracdiff                1.5_2             r41h64d53c3_0    conda-forge
r-fs                      1.5.2             r41h7525677_2    conda-forge
r-generics                0.1.3             r41hc72bb7e_1    conda-forge
r-ggplot2                 3.4.0             r41hc72bb7e_0    conda-forge
r-glue                    1.6.2             r41h06615bd_1    conda-forge
r-gtable                  0.3.1             r41hc72bb7e_1    conda-forge
r-isoband                 0.2.6             r41h7525677_1    conda-forge
r-jsonlite                1.8.3             r41h06615bd_0    conda-forge
r-labeling                0.4.2             r41hc72bb7e_2    conda-forge
r-lattice                 0.20_45           r41h06615bd_1    conda-forge
r-lifecycle               1.0.3             r41hc72bb7e_1    conda-forge
r-lmtest                  0.9_40            r41h8da6f51_1    conda-forge
r-magrittr                2.0.3             r41h06615bd_1    conda-forge
r-mass                    7.3_58.1          r41h06615bd_1    conda-forge
r-matrix                  1.5_1             r41h5f7b363_0    conda-forge
r-mgcv                    1.8_41            r41h5f7b363_0    conda-forge
r-munsell                 0.5.0           r41hc72bb7e_1005    conda-forge
r-nlme                    3.1_160           r41h8da6f51_0    conda-forge
r-nnet                    7.3_18            r41h06615bd_1    conda-forge
r-pillar                  1.8.1             r41hc72bb7e_1    conda-forge
r-pkgconfig               2.0.3             r41hc72bb7e_2    conda-forge
r-pkgload                 1.3.1             r41hc72bb7e_0    conda-forge
r-praise                  1.0.0           r41hc72bb7e_1006    conda-forge
r-processx                3.8.0             r41h06615bd_0    conda-forge
r-ps                      1.7.2             r41h06615bd_0    conda-forge
r-quadprog                1.5_8             r41hd009a43_4    conda-forge
r-quantmod                0.4.20            r41hc72bb7e_1    conda-forge
r-r6                      2.5.1             r41hc72bb7e_1    conda-forge
r-rcolorbrewer            1.1_3             r41h785f33e_1    conda-forge
r-rcpp                    1.0.9             r41h7525677_0    conda-forge
r-rcpparmadillo           0.11.4.2.1        r41h9f5de39_0    conda-forge
r-rematch2                2.1.2             r41hc72bb7e_2    conda-forge
r-rlang                   1.0.6             r41h7525677_1    conda-forge
r-rprojroot               2.0.3             r41hc72bb7e_1    conda-forge
r-scales                  1.2.1             r41hc72bb7e_1    conda-forge
r-testthat                3.1.5             r41h7525677_1    conda-forge
r-tibble                  3.1.8             r41h06615bd_1    conda-forge
r-timedate                4021.106          r41hc72bb7e_1    conda-forge
r-tseries                 0.10_52           r41hd009a43_0    conda-forge
r-ttr                     0.24.3            r41h06615bd_1    conda-forge
r-urca                    1.3_3             r41h8da6f51_0    conda-forge
r-utf8                    1.2.2             r41h06615bd_1    conda-forge
r-vctrs                   0.5.0             r41h7525677_0    conda-forge
r-viridislite             0.4.1             r41hc72bb7e_1    conda-forge
r-waldo                   0.4.0             r41hc72bb7e_1    conda-forge
r-withr                   2.5.0             r41hc72bb7e_1    conda-forge
r-xts                     0.12.2            r41h06615bd_0    conda-forge
r-zoo                     1.8_11            r41h06615bd_1    conda-forge
readline                  8.1.2                h0f457ee_0    conda-forge
sed                       4.8                  he412f7d_0    conda-forge
sysroot_linux-64          2.12                he073ed8_15    conda-forge
tk                        8.6.12               h27826a3_0    conda-forge
tktable                   2.10                 hb7b940f_3    conda-forge
xorg-kbproto              1.0.7             h7f98852_1002    conda-forge
xorg-libice               1.0.10               h7f98852_0    conda-forge
xorg-libsm                1.2.3             hd9c2040_1000    conda-forge
xorg-libx11               1.7.2                h7f98852_0    conda-forge
xorg-libxau               1.0.9                h7f98852_0    conda-forge
xorg-libxdmcp             1.1.3                h7f98852_0    conda-forge
xorg-libxext              1.3.4                h7f98852_1    conda-forge
xorg-libxrender           0.9.10            h7f98852_1003    conda-forge
xorg-libxt                1.2.1                h7f98852_2    conda-forge
xorg-renderproto          0.11.1            h7f98852_1002    conda-forge
xorg-xextproto            7.3.0             h7f98852_1002    conda-forge
xorg-xproto               7.0.31            h7f98852_1007    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge
zlib                      1.2.13               h166bdaf_4    conda-forge
zstd                      1.5.2                h6239696_4    conda-forge

Example 4-1 Use the packages in the Conda environment

The following example shows the use of the available packages in the installed and activated environment.

  1. Load libraries and suppress warnings.

    %r
    
    library(ggplot2)
    library(forecast)
  2. Load and prepare data.

    %r
    
    data("AirPassengers")
    # Through the end of 1956, no months in 1957
    air.train <- window(AirPassengers, end = 1956+11/12)
    # everything in 1957 and beyond
    air.test  <- window(AirPassengers, start = 1957)
    n.test <- length(air.test)
    
  3. Fit an arima model to the data and compute performance.

    %r
    
    air.model <- auto.arima(air.train)
  4. Create multi-step forecasts for each day

    %r
    
    accuracy(air.model)
    air.multi.forecast <- air.model %>% forecast(h = n.test)
    air.multi.forecast %>% autoplot()

    The output is similar to the following:

    Figure 4-1 Multi-step Forecasts for each Day


    multi-step forecasts for each day

  5. Compare performance to the test data.

    %r
    
    accuracy(air.multi.forecast, x = air.test)
    air.multi.forecast %>%
      autoplot() +
      geom_line(
        aes(
          x = as.numeric(time(air.test)),
          y = as.numeric(air.test)
        ),
        col = "red"
      )

    The output of the example is the following.

    Figure 4-2 Performance of Test and Training Data Set



Example 4-2 Create a function and save it to the OML4R script repository

With OML4R, functions are saved to the script repository as strings so they can be run in embedded R execution. Create a function multi.forecast, after verifying the function behaves as expected, save it to the OML4R script repository.

%r

multi.forecast <- function() {
	library(forecast)
	library(ggplot2)
	data("AirPassengers")
        air.train <- window(AirPassengers, end = 1956+11/12)
        air.test  <- window(AirPassengers, start = 1957)
        n.test <- length(air.test)
	air.model <- auto.arima(air.train)
	accuracy(air.model)
	air.multi.forecast <- air.model %>% forecast(h = n.test)
	air.multi.forecast %>% autoplot()
	res <- accuracy(air.multi.forecast, x = air.test)
	print(air.multi.forecast %>%
		autoplot() + geom_line(
		aes(x = as.numeric(time(air.test)), y = as.numeric(air.test)), col = "red"))
	return(res)}

Run the user-defined function in R.

%r

multi.forecast()

The output of the example is the following.

Figure 4-3 Performance of Test and Training Data Set



Run the user-defined function using the R API for embedded R execution.


%r

ore.doEval(FUN=multi.forecast, ore.graphics=TRUE)

The output of the example is the following:

Figure 4-4 Performance of Test and Training Data Set



Use the ore.scriptCreate function to store a single user-defined R function in the OML4R script repository. The parameter "multi.forecast" is a string that specifies the name of the user-defined function. The parameter multi.forecast is the R function to run.


%r

ore.scriptCreate("multi.forecast", multi.forecast, overwrite=TRUE)

Use the R API for embedded R execution to run the user-defined R function you saved in the script repository. Run the user-defined function by referencing it as a named script


%r
ore.doEval(FUN.NAME="multi.forecast", ore.graphics=TRUE)

The output of the example is the following:

Figure 4-5 Performance of Test and Training Data Set



Deactivate the current environment

Use the deactivate command to deactivate an enviroment.

Note:

At a given time, only one active environment is supported. So, a newly activated environment would replace an old environment. As a best practice, deactivate an environment before logging off.
%conda

deactivate
Conda environment deactivated