
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\Rtmp2tfX0e\temp_file_431c6cd62139\stringr/DESCRIPTION' ... checking for file 'C:\Users\I0555262\AppData\Local\Temp\Rtmp2tfX0e\temp_file_431c6cd62139\stringr/DESCRIPTION' ... ✔ checking for file 'C:\Users\I0555262\AppData\Local\Temp\Rtmp2tfX0e\temp_file_431c6cd62139\stringr/DESCRIPTION' (386ms)
#> ─ preparing 'stringr': (544ms)
#> 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 (386ms)
#> ─ 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/Rtmp2tfX0e/file431c1697912/stringr.Rcheck' (419ms)
#> ─ 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' (666ms)
#> ✔ 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.1s)
#> 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.1s)
#> 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 (4.7s)
#> checking installed package size ... checking installed package size ... ✔ checking installed package size (574ms)
#> ✔ checking package directory
#> checking DESCRIPTION meta-information ... checking DESCRIPTION meta-information ... ✔ checking DESCRIPTION meta-information (594ms)
#> ✔ 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 (568ms)
#> checking package subdirectories ... checking package subdirectories ... ✔ checking package subdirectories (580ms)
#> 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 (576ms)
#> 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 (561ms)
#> checking whether the package can be unloaded cleanly ... checking whether the package can be unloaded cleanly ... ✔ checking whether the package can be unloaded cleanly (676ms)
#> 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 (453ms)
#> checking whether the namespace can be unloaded cleanly ... checking whether the namespace can be unloaded cleanly ... ✔ checking whether the namespace can be unloaded cleanly (659ms)
#> checking dependencies in R code ... checking dependencies in R code ... ✔ checking dependencies in R code (691ms)
#> checking S3 generic/method consistency ... checking S3 generic/method consistency ... ✔ checking S3 generic/method consistency (1.1s)
#> checking replacement functions ... checking replacement functions ... ✔ checking replacement functions (555ms)
#> checking foreign function calls ... checking foreign function calls ... ✔ checking foreign function calls (667ms)
#> checking R code for possible problems ... checking R code for possible problems ... ✔ checking R code for possible problems (4s)
#> checking Rd files ... checking Rd files ... ✔ checking Rd files (654ms)
#> checking Rd metadata ... checking Rd metadata ... ✔ checking Rd metadata
#> checking Rd cross-references ... checking Rd cross-references ... ✔ checking Rd cross-references (357ms)
#> checking for missing documentation entries ... checking for missing documentation entries ... ✔ checking for missing documentation entries (571ms)
#> checking for code/documentation mismatches ... checking for code/documentation mismatches ... ✔ checking for code/documentation mismatches (1.8s)
#> checking Rd \usage sections ... checking Rd \usage sections ... ✔ checking Rd \usage sections (1.6s)
#> 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 (685ms)
#> 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 (365ms)
#> ✔ checking LazyData
#> checking data for ASCII and uncompressed saves ... checking data for ASCII and uncompressed saves ... ✔ checking data for ASCII and uncompressed saves (346ms)
#> 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 (449ms)
#> Running 'testthat.R' ✔ Running 'testthat.R' (15.5s)
#>
#>
#> ERROR: Unknown command "TMPDIR=C:/Users/I0555262/AppData/Local/Temp/RtmpO6o6HX/file650c5886326". Did you mean command "create-project"?
#>
#> Error: Unknown command "TMPDIR=C:/Users/I0555262/AppData/Local/Temp/RtmpO6o6HX/file650c5886326". 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/RtmpO6o6HX/file650c5886326 -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\Rtmp2tfX0e\temp_file_431c2eaf7ad\stringr/DESCRIPTION' ... checking for file 'C:\Users\I0555262\AppData\Local\Temp\Rtmp2tfX0e\temp_file_431c2eaf7ad\stringr/DESCRIPTION' ... checking for file 'C:\Users\I0555262\AppData\Local\Temp\Rtmp2tfX0e\temp_file_431c2eaf7ad\stringr/DESCRIPTION' ... checking for file 'C:\Users\I0555262\AppData\Local\Temp\Rtmp2tfX0e\temp_file_431c2eaf7ad\stringr/DESCRIPTION' ... ✔ checking for file 'C:\Users\I0555262\AppData\Local\Temp\Rtmp2tfX0e\temp_file_431c2eaf7ad\stringr/DESCRIPTION' (579ms)
#> ─ preparing 'stringr': (1s)
#> 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 vignette meta-information ... ✔ checking vignette meta-information
#> ─ checking for LF line-endings in source and make files and shell scripts (710ms)
#> ─ 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/Rtmp2tfX0e/file431c5fd27598/stringr.Rcheck' (680ms)
#> ─ 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' (1.2s)
#> 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 (4.3s)
#> 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 if there is a namespace
#> checking for executable files ... checking for executable files ... ✔ checking for executable files (2.9s)
#> 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 (9.5s)
#> checking installed package size ... checking installed package size ... ✔ checking installed package size (686ms)
#> checking package directory ... ✔ checking package directory
#> checking DESCRIPTION meta-information ... checking DESCRIPTION meta-information ... ✔ checking DESCRIPTION meta-information (878ms)
#> checking top-level files ... ✔ 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 (1s)
#> checking package subdirectories ... checking package subdirectories ... ✔ checking package subdirectories (1s)
#> checking R files for non-ASCII characters ... checking R files for non-ASCII characters ... ✔ checking R files for non-ASCII characters (375ms)
#> checking R files for syntax errors ... checking R files for syntax errors ... ✔ checking R files for syntax errors (351ms)
#> checking whether the package can be loaded ... checking whether the package can be loaded ... ✔ checking whether the package can be loaded (1.1s)
#> 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 (1s)
#> checking whether the package can be unloaded cleanly ... checking whether the package can be unloaded cleanly ... ✔ checking whether the package can be unloaded cleanly (1s)
#> 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 (798ms)
#> checking whether the namespace can be unloaded cleanly ... checking whether the namespace can be unloaded cleanly ... ✔ checking whether the namespace can be unloaded cleanly (1s)
#> checking dependencies in R code ... checking dependencies in R code ... ✔ checking dependencies in R code (1.2s)
#> checking S3 generic/method consistency ... checking S3 generic/method consistency ... ✔ checking S3 generic/method consistency (2s)
#> checking replacement functions ... checking replacement functions ... ✔ checking replacement functions (1s)
#> checking foreign function calls ... checking foreign function calls ... ✔ checking foreign function calls (1.1s)
#> checking R code for possible problems ... checking R code for possible problems ... ✔ checking R code for possible problems (7.1s)
#> checking Rd files ... checking Rd files ... ✔ checking Rd files (1.2s)
#> checking Rd metadata ... checking Rd metadata ... ✔ checking Rd metadata
#> checking Rd cross-references ... checking Rd cross-references ... ✔ checking Rd cross-references (468ms)
#> checking for missing documentation entries ... checking for missing documentation entries ... ✔ checking for missing documentation entries (1s)
#> checking for code/documentation mismatches ... checking for code/documentation mismatches ... ✔ checking for code/documentation mismatches (3.1s)
#> checking Rd \usage sections ... checking Rd \usage sections ... ✔ checking Rd \usage sections (2.8s)
#> checking Rd contents ... checking Rd contents ... ✔ checking Rd contents (468ms)
#> checking for unstated dependencies in examples ... checking for unstated dependencies in examples ... ✔ checking for unstated dependencies in examples (1s)
#> 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 (683ms)
#> ✔ checking LazyData
#> checking data for ASCII and uncompressed saves ... checking data for ASCII and uncompressed saves ... ✔ checking data for ASCII and uncompressed saves (571ms)
#> 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 (700ms)
#> Running 'testthat.R' ✔ Running 'testthat.R' (21.4s)
#>
#>
#> ERROR: Unknown command "TMPDIR=C:/Users/I0555262/AppData/Local/Temp/RtmpCCuOI0/file74541f697396". Did you mean command "create-project"?
#>
#> Error: Unknown command "TMPDIR=C:/Users/I0555262/AppData/Local/Temp/RtmpCCuOI0/file74541f697396". 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/RtmpCCuOI0/file74541f697396 -V' had status 1
#>
str(result_strict$risk_analysis)
#> List of 2
#> $ code_coverage : chr "high"
#> $ last_month_download: chr "high"