Defined Type: r_lang::cran

Defined in:
modules/r_lang/manifests/cran.pp

Overview

SPDX-License-Identifier: Apache-2.0

Define: r_lang::cran

Facilitates installation of R packages from Comprehensive R Archive Network.

Parameters

timeout

default 300 (seconds) but may need to be larger for R packages with a lot of dependencies that take time to build (e.g. tidyverse)

ensure

default 'present' but also accepts 'absent' hoping to support 'latest' eventually

mirror

The CRAN mirror to use, by default uses automatic redirection to servers worldwide (cloud.r-project.org) but can be overridden. Refer to cran.r-project.org/mirrors.html for the full list of mirrors.

library

default '/usr/local/lib/R/site-library', used for specifying the path of the library for installing the R package

Parameters:

  • timeout (Any) (defaults to: 300)
  • ensure (Any) (defaults to: 'present')
  • mirror (Any) (defaults to: 'https://cloud.r-project.org')
  • library (Any) (defaults to: '/usr/local/lib/R/site-library')


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'modules/r_lang/manifests/cran.pp', line 26

define r_lang::cran (
    $timeout = 300,
    $ensure  = 'present',
    $mirror  = 'https://cloud.r-project.org',
    $library = '/usr/local/lib/R/site-library'
) {
    $pkg_path = "${library}/${title}"
    case $ensure {
        'absent': {
            # Since r_lang can be used on machines that don't have shiny_server,
            # we only want a package removal to restart the Shiny Server service
            # if the service actually exists:
            $remove_notify = defined(Service['shiny-server']) ? {
                true    => Service['shiny-server'],
                default => Undef,
            }
            exec { "remove-${title}":
                command => "/usr/bin/R -e \"remove.packages('${title}', lib = '${library}')\"",
                notify  => $remove_notify,
                onlyif  => "test -d ${pkg_path}",
            }
        }
        default: {
            exec { "package-${title}":
                require => [
                    Package['r-base'],
                    Package['r-base-dev']
                ],
                timeout => $timeout,
                command => "/usr/bin/R -e \"install.packages('${title}', repos = c(CRAN = '${mirror}'), lib = '${library}')\"",
                creates => $pkg_path,
            }
        }
    }
}