Overview

Overview of the R Script Module

The R script tool in APM provides a way for you to utilize R and Python programming languages to create scripts that can receive data from inputs, make calculations, and then return one or more outputs. These scripts can then be used within Policy Designer and Family Policies to expand the functionality of policies.

R and Python scripts can be as simple or as complex as you need them to be, depending on the data that you want the script to calculate. For instance, a simple script may calculate and return a value based only on two inputs. A more complex script might utilize ten inputs, and have ten different output values. This documentation does not cover the process of developing R or Python code.

R and Python Scripts in Policies and Family Policies

R and Python scripts can be used to expand the functionality of policy models in Policy Designer and Family Policies. After you create and save a script, you can use the R Script and Python nodes in your policy model to pass values into the script, and receive calculated values out of the script.

The parameters that you define in the script determine how the R Script node or Python node in your policy model will behave. Each parameter that you specify as an input appears as a field in the Properties window for the R Script node or Python node. You can then use standard policy options to provide values to the parameters in the script. Each parameter that you specify as an output determines what values subsequent nodes in the policy model can use for additional calculations or actions.

Note: Additional deployment steps must be completed before you can use the Python node

About Installed R Packages

The APM environment uses R version 4.4.2. The R packages listed in the following table are installed in the APM environment.
PackageVersion
arrow18.1.0.1
askpass1.2.1
assertthat0.2.1
backports1.5.0
base64enc0.1-3
BiocManager1.30.25
Bit4.5.0.1
bit644.6.0-1
Blob1.2.4
Brew1.0-10
Brio1.1.5
Broom1.0.7
Bslib0.8.0
Cachem1.1.0
Callr3.7.6
Cellranger1.1.0
Cli3.6.3
Clipr0.8.0
Clock0.7.2
Colorspace2.1-1
commonmark1.9.2
conflicted1.2.0
cpp110.5.1
crayon1.5.3
credentials2.0.2
curl6.2.0
data.table1.16.4
DBI1.2.3
dbplyr2.5.0
desc1.4.3
devtools2.4.5
diagram1.6.5
dials1.3.0
DiceDesign1.1
diffobj0.3.5
digest0.6.37
docopt0.7.1
doFuture1.0.1
downlit0.4.4
dplyr1.1.4
dtplyr1.3.1
duckdb1.1.3-2
ellipsis0.3.2
evaluate1.0.3
fansi1.0.6
farver2.1.2
fastmap1.2.0
fontawesome0.5.3
forcats1.0.0
foreach1.5.2
fs1.6.5
fst0.9.8
fstcore0.9.18
furrr0.3.1
future1.34.0
future.apply1.11.3
gargle1.5.2
generics0.1.3
gert2.1.4
ggplot23.5.1
gh1.4.1
gitcreds0.1.2
globals0.16.3
glue1.8.0
googledrive2.1.1
googlesheets41.1.1
gower1.0.2
GPfit1.0-8
gtable0.3.6
hardhat1.4.0
haven2.5.4
highr0.11
hms1.1.3
htmltools0.5.8.1
htmlwidgets1.6.4
httpuv1.6.15
httr1.4.7
httr21.1.0
IAPWS951.2.4
ids1.0.1
infer1.0.7
ini0.3.1
ipred0.9-15
isoband0.2.7
iterators1.0.14
jquerylib0.1.4
jsonlite1.8.9
knitr1.49
labeling0.4.3
Lahman12.0-0
later1.4.1
lava1.8.1
lhs1.2.0
lifecycle1.0.4
listenv0.9.1
littler0.3.20
lubridate1.9.4
magrittr2.0.3
memoise2.0.1
mime0.12
miniUI0.1.1.1
modeldata1.4.0
modelenv0.2.0
modelr0.1.11
munsell0.5.1
numDeriv2016.8-1.1
nycflights131.0.2
openssl2.3.1
pander0.6.5
parallelly1.41.0
parsnip1.2.1
patchwork1.3.0
pillar1.10.1
pkgbuild1.4.6
pkgconfig2.0.3
pkgdown2.1.1
pkgload1.4.0
plogr0.2.0
praise1.0.0
prettyunits1.2.0
processx3.8.5
prodlim2024.06.25
profvis0.4.0
progress1.2.3
progressr0.15.1
promises1.3.2
ps1.8.1
purrr1.0.2
R62.5.1
ragg1.3.3
rappdirs0.3.3
rcmdcheck1.4.0
RColorBrewer1.1-3
Rcpp1.0.14
RcppArmadillo14.2.2-1
readr2.1.5
readxl1.4.3
recipes1.1.0
rematch2.0.0
rematch22.1.2
remotes2.5.0
reprex2.1.1
rlang1.1.5
RMariaDB1.3.3
rmarkdown2.29
roxygen27.3.2
RPostgres1.4.7
rprojroot2.0.4
rsample1.2.1
Rserve1.8-15
RSQLite2.3.9
rstudioapi0.17.1
rversions2.1.2
rvest1.0.4
sass0.4.9
scales1.3.0
selectr0.4-2
sessioninfo1.2.2
sfd0.1.0
shape1.4.6.1
shiny1.10.0
slider0.3.2
sourcetools0.1.7-1
SQUAREM2021.1
stringi1.8.4
stringr1.5.1
sys3.4.3
systemfonts1.2.1
testthat3.2.3
textshaping1.0.0
tibble3.2.1
tidymodels1.2.0
tidyr1.3.1
tidyselect1.2.1
tidyverse2.0.0
timechange0.3.0
timeDate4041.11
tinytex0.54
tune1.2.1
tzdb0.4.0
urlchecker1.0.1
usethis3.1.0
utf81.2.4
uuid1.2-1
vctrs0.6.5
viridisLite0.4.2
vroom1.6.5
waldo0.6.1
warp0.2.1
WeibullR1.2.1
whisker0.4.1
withr3.0.2
workflows1.1.4
workflowsets1.1.0
xfun0.5
xml21.3.6
xopen1.0.1
xtable1.8-4
yaml2.3.10
yardstick1.3.2
zip2.3.1
Your R script must load any libraries that you want to use from these packages at run time using the library() function. The following R script example loads the WeibullR package and uses the AbPval (Abernethy’s P Value) function:
library(WeibullR)
answer <- AbPval(50, 0.996, "lnorm")
Note: APM does not support run-time loading of additional R packages. Some installed package functions may not be operable in the APM environment. R scripts cannot access resources outside the APM environment (for example, Google Drive).

Access a Script

Procedure

  1. In the Applications menu, navigate to the TOOLS section, and then select R Scripts.

    The R Scripts page appears.



    Note: Only R or Python scripts created or accessed from the R Scripts page appear in this list. The 25 most recently accessed scripts will appear in the list.
  2. Choose one of the following:
    • Select an R or Python script from the grid.
    • Browse the Catalog to select a script. To do so:
      1. Select Browse.

        The Select a rscript from the catalog window appears.

      2. Select an R or Python script.
      3. Select Open.
    A new page appears, displaying the selected script.

R and Python Script Workflow

This workflow provides the basic, high-level steps for using this module. The steps and links in this workflow do not reference every possible procedure.

  1. Create a new R script.
  2. Enter R or Python code in the script editor.
  3. Define each parameter in the R script.
  4. Save the R or Python script.
  5. Create a policy containing the R Script or Python node in order to execute the script.