
Risk Assessment with Custom Configurations
Source:vignettes/define_custom_risk_rules.Rmd
define_custom_risk_rules.RmdIntroduction
The assess_pkg_r_package() function in the
risk.assessr package allows users to evaluate the risk of
an R package. You can pass a custom risk configuration to control how
risk levels are interpreted.
This vignette demonstrates:
- Running the function with the default risk configuration
- Running it with two different custom configurations
Load the Package
library(risk.assessr)
options(repos = c(CRAN = "http://cran.us.r-project.org"))Example 1: Use Default Configuration
result_default <- risk.assessr::assess_pkg_r_package("stringr")
#> ── R CMD build ─────────────────────────────────────────────────────────────────
#> ✔ checking for file 'C:\Users\I0555262\AppData\Local\Temp\RtmpQlp92E\temp_file_3b881df2347\stringr/DESCRIPTION'
#> ─ preparing 'stringr': (385ms)
#> checking DESCRIPTION meta-information ... checking DESCRIPTION meta-information ... checking DESCRIPTION meta-information ... checking DESCRIPTION meta-information ... ✔ checking DESCRIPTION meta-information
#> ✔ checking vignette meta-information
#> ─ checking for LF line-endings in source and make files and shell scripts
#> ─ checking for empty or unneeded directories
#> ─ building 'stringr_1.6.0.tar.gz'
#>
#> ── R CMD check ─────────────────────────────────────────────────────────────────
#> ─ using log directory 'C:/Users/I0555262/AppData/Local/Temp/RtmpQlp92E/file3b8843682d1a/stringr.Rcheck' (472ms)
#> ─ using R version 4.2.2 (2022-10-31 ucrt)
#> ─ using platform: x86_64-w64-mingw32 (64-bit)
#> ─ using session charset: UTF-8
#> ─ using options '--no-examples --no-manual --ignore-vignettes' (568ms)
#> ✔ checking for file 'stringr/DESCRIPTION'
#> ─ this is package 'stringr' version '1.6.0'
#> ─ package encoding: UTF-8
#> checking package namespace information ... checking package namespace information ... ✔ checking package namespace information
#> checking package dependencies ... checking package dependencies ... ✔ checking package dependencies (2.9s)
#> checking if this is a source package ... checking if this is a source package ... ✔ checking if this is a source package
#> ✔ checking if there is a namespace
#> checking for executable files ... checking for executable files ... ✔ checking for executable files (2.2s)
#> checking for hidden files and directories ... checking for hidden files and directories ... ✔ checking for hidden files and directories
#> checking for portable file names ... checking for portable file names ... ✔ checking for portable file names
#> checking whether package 'stringr' can be installed ... checking whether package 'stringr' can be installed ... ✔ checking whether package 'stringr' can be installed (3.8s)
#> checking installed package size ... checking installed package size ... ✔ checking installed package size (561ms)
#> checking package directory ... ✔ checking package directory
#> checking DESCRIPTION meta-information ... checking DESCRIPTION meta-information ... ✔ checking DESCRIPTION meta-information (389ms)
#> ✔ checking top-level files
#> checking for left-over files ... checking for left-over files ... ✔ checking for left-over files
#> checking index information ... checking index information ... ✔ checking index information
#> checking package subdirectories ... checking package subdirectories ... ✔ checking package subdirectories (348ms)
#> checking R files for non-ASCII characters ... checking R files for non-ASCII characters ... ✔ checking R files for non-ASCII characters
#> checking R files for syntax errors ... checking R files for syntax errors ... ✔ checking R files for syntax errors
#> checking whether the package can be loaded ... checking whether the package can be loaded ... ✔ checking whether the package can be loaded (552ms)
#> checking whether the package can be loaded with stated dependencies ... checking whether the package can be loaded with stated dependencies ... ✔ checking whether the package can be loaded with stated dependencies (565ms)
#> checking whether the package can be unloaded cleanly ... checking whether the package can be unloaded cleanly ... ✔ checking whether the package can be unloaded cleanly (570ms)
#> checking whether the namespace can be loaded with stated dependencies ... checking whether the namespace can be loaded with stated dependencies ... ✔ checking whether the namespace can be loaded with stated dependencies (552ms)
#> checking whether the namespace can be unloaded cleanly ... checking whether the namespace can be unloaded cleanly ... ✔ checking whether the namespace can be unloaded cleanly (664ms)
#> checking dependencies in R code ... checking dependencies in R code ... ✔ checking dependencies in R code (555ms)
#> checking S3 generic/method consistency ... checking S3 generic/method consistency ... ✔ checking S3 generic/method consistency (1s)
#> checking replacement functions ... checking replacement functions ... ✔ checking replacement functions (467ms)
#> checking foreign function calls ... checking foreign function calls ... ✔ checking foreign function calls (552ms)
#> checking R code for possible problems ... checking R code for possible problems ... ✔ checking R code for possible problems (3.3s)
#> checking Rd files ... checking Rd files ... ✔ checking Rd files (553ms)
#> checking Rd metadata ... checking Rd metadata ... ✔ checking Rd metadata
#> checking Rd cross-references ... checking Rd cross-references ... ✔ checking Rd cross-references
#> checking for missing documentation entries ... checking for missing documentation entries ... ✔ checking for missing documentation entries (467ms)
#> checking for code/documentation mismatches ... checking for code/documentation mismatches ... ✔ checking for code/documentation mismatches (1.6s)
#> checking Rd \usage sections ... checking Rd \usage sections ... ✔ checking Rd \usage sections (1.5s)
#> checking Rd contents ... checking Rd contents ... ✔ checking Rd contents (352ms)
#> checking for unstated dependencies in examples ... checking for unstated dependencies in examples ... ✔ checking for unstated dependencies in examples (458ms)
#> checking contents of 'data' directory ... checking contents of 'data' directory ... ✔ checking contents of 'data' directory
#> checking data for non-ASCII characters ... checking data for non-ASCII characters ... ✔ checking data for non-ASCII characters (336ms)
#> checking LazyData ... ✔ checking LazyData
#> checking data for ASCII and uncompressed saves ... checking data for ASCII and uncompressed saves ... ✔ checking data for ASCII and uncompressed saves
#> checking installed files from 'inst/doc' ... checking installed files from 'inst/doc' ... ✔ checking installed files from 'inst/doc'
#> ─ checking files in 'vignettes' ... SKIPPED
#> ─ checking examples ... SKIPPED
#> checking for unstated dependencies in 'tests' ... checking for unstated dependencies in 'tests' ... ✔ checking for unstated dependencies in 'tests'
#> checking tests ... ─ checking tests
#> Running 'testthat.R' ✔ Running 'testthat.R' (9s)
#>
#>
#> ERROR: Unknown command "TMPDIR=C:/Users/I0555262/AppData/Local/Temp/RtmpEJjH0z/file641410af531a". Did you mean command "create-project"?
#>
#> Error: Unknown command "TMPDIR=C:/Users/I0555262/AppData/Local/Temp/RtmpEJjH0z/file641410af531a". Did you mean command "create-project"?
#> at Command.parseArguments (file:///C:/PROGRA~1/Quarto/bin/quarto.js:8553:31)
#> at Command.parseCommand (file:///C:/PROGRA~1/Quarto/bin/quarto.js:8320:31)
#> at async quarto (file:///C:/PROGRA~1/Quarto/bin/quarto.js:127535:5)
#> at async file:///C:/PROGRA~1/Quarto/bin/quarto.js:127553:9
#> Warning message:
#> In system2("quarto", "-V", stdout = TRUE, env = paste0("TMPDIR=", :
#> running command '"quarto" TMPDIR=C:/Users/I0555262/AppData/Local/Temp/RtmpEJjH0z/file641410af531a -V' had status 1
#>
str(result_default$risk_analysis)
#> List of 8
#> $ dependencies_count : chr "low"
#> $ later_version : chr "low"
#> $ code_coverage : chr "low"
#> $ total_download : chr "low"
#> $ license : chr "low"
#> $ reverse_dependencies_count: chr "low"
#> $ documentation_score : chr "low"
#> $ cmd_check : chr "low"Example 2: Use Custom Configuration (Strict Code Coverage)
strict_coverage_config <- list(
list(
label = "code coverage",
id = "code_coverage",
key = "code_coverage",
thresholds = list(
list(level = "high", max = 0.9999),
list(level = "low", max = NULL)
)
),
list(
label = "popularity",
id = "popularity",
key = "last_month_download",
thresholds = list(
list(level = "high", max = 21200000),
list(level = "medium", max = 11200000),
list(level = "low", max = NULL)
)
)
)
# Set the option
options(risk.assessr.risk_definition = strict_coverage_config)
result_strict <- risk.assessr::assess_pkg_r_package("stringr")
#> ── R CMD build ─────────────────────────────────────────────────────────────────
#> checking for file 'C:\Users\I0555262\AppData\Local\Temp\RtmpQlp92E\temp_file_3b8828e13013\stringr/DESCRIPTION' ... checking for file 'C:\Users\I0555262\AppData\Local\Temp\RtmpQlp92E\temp_file_3b8828e13013\stringr/DESCRIPTION' ... ✔ checking for file 'C:\Users\I0555262\AppData\Local\Temp\RtmpQlp92E\temp_file_3b8828e13013\stringr/DESCRIPTION' (343ms)
#> ─ preparing 'stringr': (364ms)
#> checking DESCRIPTION meta-information ... checking DESCRIPTION meta-information ... checking DESCRIPTION meta-information ... checking DESCRIPTION meta-information ... ✔ checking DESCRIPTION meta-information
#> checking vignette meta-information ... checking vignette meta-information ... ✔ checking vignette meta-information
#> ─ checking for LF line-endings in source and make files and shell scripts
#> ─ checking for empty or unneeded directories
#> ─ building 'stringr_1.6.0.tar.gz'
#>
#> ── R CMD check ─────────────────────────────────────────────────────────────────
#> ─ using log directory 'C:/Users/I0555262/AppData/Local/Temp/RtmpQlp92E/file3b8861fe6050/stringr.Rcheck' (372ms)
#> ─ using R version 4.2.2 (2022-10-31 ucrt)
#> ─ using platform: x86_64-w64-mingw32 (64-bit)
#> ─ using session charset: UTF-8
#> ─ using options '--no-examples --no-manual --ignore-vignettes' (538ms)
#> checking for file 'stringr/DESCRIPTION' ... ✔ checking for file 'stringr/DESCRIPTION'
#> ─ this is package 'stringr' version '1.6.0'
#> ─ package encoding: UTF-8
#> checking package namespace information ... checking package namespace information ... ✔ checking package namespace information
#> checking package dependencies ... checking package dependencies ... ✔ checking package dependencies (3.2s)
#> checking if this is a source package ... checking if this is a source package ... ✔ checking if this is a source package
#> ✔ checking if there is a namespace
#> checking for executable files ... checking for executable files ... ✔ checking for executable files (2.2s)
#> checking for hidden files and directories ... checking for hidden files and directories ... ✔ checking for hidden files and directories
#> checking for portable file names ... checking for portable file names ... ✔ checking for portable file names
#> checking whether package 'stringr' can be installed ... checking whether package 'stringr' can be installed ... ✔ checking whether package 'stringr' can be installed (3.9s)
#> checking installed package size ... checking installed package size ... ✔ checking installed package size (767ms)
#> ✔ checking package directory
#> checking DESCRIPTION meta-information ... checking DESCRIPTION meta-information ... ✔ checking DESCRIPTION meta-information (505ms)
#> ✔ checking top-level files
#> checking for left-over files ... checking for left-over files ... ✔ checking for left-over files
#> checking index information ... checking index information ... ✔ checking index information (352ms)
#> checking package subdirectories ... checking package subdirectories ... ✔ checking package subdirectories (360ms)
#> checking R files for non-ASCII characters ... checking R files for non-ASCII characters ... ✔ checking R files for non-ASCII characters
#> checking R files for syntax errors ... checking R files for syntax errors ... ✔ checking R files for syntax errors
#> checking whether the package can be loaded ... checking whether the package can be loaded ... ✔ checking whether the package can be loaded (549ms)
#> checking whether the package can be loaded with stated dependencies ... checking whether the package can be loaded with stated dependencies ... ✔ checking whether the package can be loaded with stated dependencies (436ms)
#> checking whether the package can be unloaded cleanly ... checking whether the package can be unloaded cleanly ... ✔ checking whether the package can be unloaded cleanly (566ms)
#> checking whether the namespace can be loaded with stated dependencies ... checking whether the namespace can be loaded with stated dependencies ... ✔ checking whether the namespace can be loaded with stated dependencies (452ms)
#> checking whether the namespace can be unloaded cleanly ... checking whether the namespace can be unloaded cleanly ... ✔ checking whether the namespace can be unloaded cleanly (554ms)
#> checking dependencies in R code ... checking dependencies in R code ... ✔ checking dependencies in R code (565ms)
#> checking S3 generic/method consistency ... checking S3 generic/method consistency ... ✔ checking S3 generic/method consistency (985ms)
#> checking replacement functions ... checking replacement functions ... ✔ checking replacement functions (466ms)
#> checking foreign function calls ... checking foreign function calls ... ✔ checking foreign function calls (552ms)
#> checking R code for possible problems ... checking R code for possible problems ... ✔ checking R code for possible problems (3.4s)
#> checking Rd files ... checking Rd files ... ✔ checking Rd files (534ms)
#> checking Rd metadata ... checking Rd metadata ... ✔ checking Rd metadata
#> checking Rd cross-references ... checking Rd cross-references ... ✔ checking Rd cross-references
#> checking for missing documentation entries ... checking for missing documentation entries ... ✔ checking for missing documentation entries (451ms)
#> checking for code/documentation mismatches ... checking for code/documentation mismatches ... ✔ checking for code/documentation mismatches (1.6s)
#> checking Rd \usage sections ... checking Rd \usage sections ... ✔ checking Rd \usage sections (1.4s)
#> checking Rd contents ... checking Rd contents ... ✔ checking Rd contents
#> checking for unstated dependencies in examples ... checking for unstated dependencies in examples ... ✔ checking for unstated dependencies in examples (471ms)
#> checking contents of 'data' directory ... checking contents of 'data' directory ... ✔ checking contents of 'data' directory
#> checking data for non-ASCII characters ... checking data for non-ASCII characters ... ✔ checking data for non-ASCII characters
#> ✔ checking LazyData
#> checking data for ASCII and uncompressed saves ... checking data for ASCII and uncompressed saves ... ✔ checking data for ASCII and uncompressed saves (335ms)
#> checking installed files from 'inst/doc' ... checking installed files from 'inst/doc' ... ✔ checking installed files from 'inst/doc'
#> ─ checking files in 'vignettes' ... SKIPPED
#> ─ checking examples ... SKIPPED
#> checking for unstated dependencies in 'tests' ... checking for unstated dependencies in 'tests' ... ✔ checking for unstated dependencies in 'tests'
#> checking tests ... ─ checking tests
#> Running 'testthat.R' ✔ Running 'testthat.R' (9s)
#>
#>
#> ERROR: Unknown command "TMPDIR=C:/Users/I0555262/AppData/Local/Temp/RtmpOA8V5R/file69c6c6d2336". Did you mean command "create-project"?
#>
#> Error: Unknown command "TMPDIR=C:/Users/I0555262/AppData/Local/Temp/RtmpOA8V5R/file69c6c6d2336". Did you mean command "create-project"?
#> at Command.parseArguments (file:///C:/PROGRA~1/Quarto/bin/quarto.js:8553:31)
#> at Command.parseCommand (file:///C:/PROGRA~1/Quarto/bin/quarto.js:8320:31)
#> at async quarto (file:///C:/PROGRA~1/Quarto/bin/quarto.js:127535:5)
#> at async file:///C:/PROGRA~1/Quarto/bin/quarto.js:127553:9
#> Warning message:
#> In system2("quarto", "-V", stdout = TRUE, env = paste0("TMPDIR=", :
#> running command '"quarto" TMPDIR=C:/Users/I0555262/AppData/Local/Temp/RtmpOA8V5R/file69c6c6d2336 -V' had status 1
#>
str(result_strict$risk_analysis)
#> List of 2
#> $ code_coverage : chr "high"
#> $ last_month_download: chr "high"