Product: TIBCO Spotfire®
Example TERR script that installs a group of CRAN packages before loading them via calls to library()
This article provides an example TERR script that installs a group of CRAN packages before loading them via calls to library().
The example TERR script shown below installs a selected group of CRAN packages before loading them via calls to library().
The script only uses core functionality that is built into TIBCO Enterprise Runtime for R (TERR).
#-----
PackagesToLoad <- c("dbscan", "plyr", "dplyr")
PkgsToInstall <- setdiff(PackagesToLoad, rownames(installed.packages()))
if( length(PkgsToInstall) )
{
install.packages(PkgsToInstall)
}
# Wait for the selected packages and
# any other packages they depend on
# to be downloaded and installed.
# There will be informational messages
# for each package.
sapply(
X = PackagesToLoad,
FUN = function(X) library(X, character.only = TRUE))
#-----
The following is an example of its use, in a TERR 5.0.0 Console session on a Windows machine that has internet access to the open-source R community's CRAN repository:
=====
TIBCO Software Inc. Confidential Information
Copyright (C) 2011-2019 TIBCO Software Inc. ALL RIGHTS RESERVED
TIBCO Enterprise Runtime for R version 5.0.0 for Microsoft Windows 64-bit
Type 'help()' for help.
Type 'q()' to quit.
>
>
>
> R.home()
[1] "C:/Program Files/TIBCO/terr500"
>
>
> version$version.string
[1] "TIBCO Enterprise Runtime for R version 5.0.0 (2019-01-15)"
>
>
> getRversion()
[1] '3.5.1'
>
>
> installed.packages(lib = .libPaths()[1])[, "Version"]
character(0)
>
>
>
> search()
[1] ".GlobalEnv" "package:stats" "package:graphics"
[4] "package:grDevices" "package:utils" "package:methods"
[7] "package:base"
>
>
>
>
>
> #-----
> PackagesToLoad <- c("dbscan", "plyr", "dplyr")
>
> PkgsToInstall <- setdiff(PackagesToLoad, rownames(installed.packages()))
>
> if( length(PkgsToInstall) )
{
install.packages(PkgsToInstall)
}
>
> # ...
>
> # Wait for the selected packages and
> # any other packages they depend on
> # to be downloaded and installed.
> # There will be informational messages
> # for each package.
>
> sapply(
X = PackagesToLoad,
FUN = function(X) library(X, character.only = TRUE))
The following object(s) are masked _from_ 'package:plyr':
arrange, count, desc, failwith, id, mutate, rename, summarise, summarize
The following object(s) are masked _from_ 'package:stats':
filter, lag
The following object(s) are masked _from_ 'base':
intersect, setdiff, setequal, union
$dbscan
[1] "dbscan" "stats" "graphics" "grDevices" "utils" "methods"
[7] "base"
$plyr
[1] "plyr" "dbscan" "stats" "graphics" "grDevices" "utils"
[7] "methods" "base"
$dplyr
[1] "dplyr" "plyr" "dbscan" "stats" "graphics" "grDevices"
[7] "utils" "methods" "base"
> #-----
>
>
>
> search()
[1] ".GlobalEnv" "package:dplyr" "package:plyr"
[4] "package:dbscan" "package:stats" "package:graphics"
[7] "package:grDevices" "package:utils" "package:methods"
[10] "package:base"
>
>
>
> installed.packages(lib = .libPaths()[1])[, "Version"]
BH R6 Rcpp assertthat bindr bindrcpp cli
"1.69.0-1" "2.4.0" "1.0.1" "0.2.1" "0.1.1" "0.2.2" "1.1.0"
crayon dbscan dplyr fansi glue magrittr pillar
"1.3.4" "1.1-3" "0.7.8" "0.4.0" "1.3.1" "1.5" "1.3.1"
pkgconfig plogr plyr purrr rlang tibble tidyselect
"2.0.2" "0.2.0" "1.8.4" "0.3.2" "0.3.3" "2.1.1" "0.2.5"
utf8
"1.1.4"
>
>
=====
Disclaimer:
The code in this article is only a sample to be used as a reference. It is not intended to be used "As Is" in a Production environment. Always test in a Development environment. Make modifications to the code in accordance with your implementation specifications that best suit your business requirements. Refer to the reference(s) cited in this article for usage of the functions and methods used in the code.
Important note on use of CRAN packages:
User-contributed R packages from the open-source R community's CRAN repository (https://cran.r-project.org/) are available under separate open source software license terms and are not part of the TIBCO Spotfire product line. As such, user-contributed CRAN packages are not within the scope of your license for any TIBCO Spotfire product. User-contributed CRAN packages are not supported, maintained, or warranted in any way by TIBCO Software Inc. Download and use of CRAN packages is solely at your own discretion and subject to the free open source license terms applicable to each individual package.
In a TERR Console session, the following commands will open online help topics for TERR functions, operators, objects and syntax structures (such as the if() clause) used in this article:
?R.home
?version
?"$"
?getRversion
?installed.packages
?search
?"<-"
?c
?setdiff
?rownames
?Syntax
?length
?install.packages
?sapply
?library
Comments
0 comments
Article is closed for comments.