diff --git a/.github/workflows/lint_changed_files.yml b/.github/workflows/lint_changed_files.yml index 75d4aa9c9cea..c5da1b28f6f3 100644 --- a/.github/workflows/lint_changed_files.yml +++ b/.github/workflows/lint_changed_files.yml @@ -274,7 +274,7 @@ jobs: # Pin action to full length commit SHA uses: r-lib/actions/setup-r@6f6e5bc62fba3a704f74e7ad7ef7676c5c6a2590 # v2.11.4 with: - r-version: '3.5.3' + r-version: '4.2.0' # Lint R files: - name: 'Lint R files' diff --git a/.github/workflows/lint_random_files.yml b/.github/workflows/lint_random_files.yml index f717f630f6b4..03666d36eea8 100644 --- a/.github/workflows/lint_random_files.yml +++ b/.github/workflows/lint_random_files.yml @@ -374,7 +374,7 @@ jobs: # Pin action to full length commit SHA uses: r-lib/actions/setup-r@6f6e5bc62fba3a704f74e7ad7ef7676c5c6a2590 # v2.11.4 with: - r-version: '4.3.3' + r-version: '4.2.0' # Lint R files: - name: 'Lint R files' diff --git a/lib/node_modules/@stdlib/_tools/lint/license-header-file-list/test/fixtures/bad/file.R b/lib/node_modules/@stdlib/_tools/lint/license-header-file-list/test/fixtures/bad/file.R index ba99caea716a..b3ac4d10165b 100644 --- a/lib/node_modules/@stdlib/_tools/lint/license-header-file-list/test/fixtures/bad/file.R +++ b/lib/node_modules/@stdlib/_tools/lint/license-header-file-list/test/fixtures/bad/file.R @@ -9,7 +9,7 @@ options( digits = 16L ); #' main(); main <- function() { # Define benchmark parameters: - name <- "abs"; + name <- 'abs'; iterations <- 1000000L; repeats <- 3L; @@ -18,7 +18,7 @@ main <- function() { #' @examples #' print_version(); print_version <- function() { - cat( "TAP version 13\n" ); + cat( 'TAP version 13\n' ); } #' Print the TAP summary. @@ -29,12 +29,12 @@ main <- function() { #' @examples #' print_summary( 3, 3 ); print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); + cat( '#\n' ); + cat( paste0( '1..', total, '\n' ) ); # TAP plan + cat( paste0( '# total ', total, '\n' ) ); + cat( paste0( '# pass ', passing, '\n' ) ); + cat( '#\n' ); + cat( '# ok\n' ); } #' Print benchmark results. @@ -46,18 +46,18 @@ main <- function() { #' print_results( 10000L, 0.131009101868 ); print_results <- function( iterations, elapsed ) { rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); + cat( ' ---\n' ); + cat( paste0( ' iterations: ', iterations, '\n' ) ); + cat( paste0( ' elapsed: ', elapsed, '\n' ) ); + cat( paste0( ' rate: ', rate, '\n' ) ); + cat( ' ...\n' ); } #' Run a benchmark. #' #' ## Notes #' - #' * We compute and return a total "elapsed" time, rather than the minimum + #' * We compute and return a total 'elapsed' time, rather than the minimum #' evaluation time, to match benchmark results in other languages (e.g., #' Python). #' @@ -69,9 +69,9 @@ main <- function() { #' elapsed <- benchmark( 10000L ); benchmark <- function( iterations ) { # Run the benchmarks: - results <- microbenchmark::microbenchmark( abs( (1000.0*runif(1)) - 500.0 ), times = iterations ); + results <- microbenchmark::microbenchmark( abs( (1000.0*runif(1L)) - 500.0 ), times = iterations ); - # Sum all the raw timing results to get a total "elapsed" time: + # Sum all the raw timing results to get a total 'elapsed' time: elapsed <- sum( results$time ); # Convert the elapsed time from nanoseconds to seconds: @@ -81,11 +81,11 @@ main <- function() { } print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); + for ( i in 1L:repeats ) { + cat( paste0( '# r::', name, '\n' ) ); elapsed <- benchmark( iterations ); print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); + cat( paste0( 'ok ', i, ' benchmark finished', '\n' ) ); } print_summary( repeats, repeats ); } diff --git a/lib/node_modules/@stdlib/_tools/lint/license-header-file-list/test/fixtures/good/file.R b/lib/node_modules/@stdlib/_tools/lint/license-header-file-list/test/fixtures/good/file.R index f00d33e421f3..ad07c1e85f94 100644 --- a/lib/node_modules/@stdlib/_tools/lint/license-header-file-list/test/fixtures/good/file.R +++ b/lib/node_modules/@stdlib/_tools/lint/license-header-file-list/test/fixtures/good/file.R @@ -25,7 +25,7 @@ options( digits = 16L ); #' main(); main <- function() { # Define benchmark parameters: - name <- "abs"; + name <- 'abs'; iterations <- 1000000L; repeats <- 3L; @@ -34,7 +34,7 @@ main <- function() { #' @examples #' print_version(); print_version <- function() { - cat( "TAP version 13\n" ); + cat( 'TAP version 13\n' ); } #' Print the TAP summary. @@ -45,12 +45,12 @@ main <- function() { #' @examples #' print_summary( 3, 3 ); print_summary <- function( total, passing ) { - cat( "#\n" ); - cat( paste0( "1..", total, "\n" ) ); # TAP plan - cat( paste0( "# total ", total, "\n" ) ); - cat( paste0( "# pass ", passing, "\n" ) ); - cat( "#\n" ); - cat( "# ok\n" ); + cat( '#\n' ); + cat( paste0( '1..', total, '\n' ) ); # TAP plan + cat( paste0( '# total ', total, '\n' ) ); + cat( paste0( '# pass ', passing, '\n' ) ); + cat( '#\n' ); + cat( '# ok\n' ); } #' Print benchmark results. @@ -62,18 +62,18 @@ main <- function() { #' print_results( 10000L, 0.131009101868 ); print_results <- function( iterations, elapsed ) { rate <- iterations / elapsed; - cat( " ---\n" ); - cat( paste0( " iterations: ", iterations, "\n" ) ); - cat( paste0( " elapsed: ", elapsed, "\n" ) ); - cat( paste0( " rate: ", rate, "\n" ) ); - cat( " ...\n" ); + cat( ' ---\n' ); + cat( paste0( ' iterations: ', iterations, '\n' ) ); + cat( paste0( ' elapsed: ', elapsed, '\n' ) ); + cat( paste0( ' rate: ', rate, '\n' ) ); + cat( ' ...\n' ); } #' Run a benchmark. #' #' ## Notes #' - #' * We compute and return a total "elapsed" time, rather than the minimum + #' * We compute and return a total 'elapsed' time, rather than the minimum #' evaluation time, to match benchmark results in other languages (e.g., #' Python). #' @@ -85,9 +85,9 @@ main <- function() { #' elapsed <- benchmark( 10000L ); benchmark <- function( iterations ) { # Run the benchmarks: - results <- microbenchmark::microbenchmark( abs( (1000.0*runif(1)) - 500.0 ), times = iterations ); + results <- microbenchmark::microbenchmark( abs( (1000.0*runif(1L)) - 500.0 ), times = iterations ); - # Sum all the raw timing results to get a total "elapsed" time: + # Sum all the raw timing results to get a total 'elapsed' time: elapsed <- sum( results$time ); # Convert the elapsed time from nanoseconds to seconds: @@ -97,11 +97,11 @@ main <- function() { } print_version(); - for ( i in 1:repeats ) { - cat( paste0( "# r::", name, "\n" ) ); + for ( i in 1L:repeats ) { + cat( paste0( '# r::', name, '\n' ) ); elapsed <- benchmark( iterations ); print_results( iterations, elapsed ); - cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); + cat( paste0( 'ok ', i, ' benchmark finished', '\n' ) ); } print_summary( repeats, repeats ); } diff --git a/tools/lint/r/linter.R b/tools/lint/r/linter.R index db9905591700..8761aae97b2b 100644 --- a/tools/lint/r/linter.R +++ b/tools/lint/r/linter.R @@ -25,7 +25,7 @@ # [1]: https://github.com/jimhester/lintr # Ensure that the `lintr` package is installed... -if ( !require( 'lintr', quietly = TRUE, character.only = TRUE ) ) { +if ( !requireNamespace( 'lintr', quietly = TRUE ) ) { install.packages( 'lintr', repos = 'http://lib.stat.cmu.edu/R/CRAN/', quiet = TRUE ); } @@ -38,8 +38,11 @@ if ( n == 0L ) { stop( 'Must provide at least one file to lint.', call. = FALSE ); } +# Warn on partial `$` matches as replacement for deprecated `extraction_operator_linter`: +options( warnPartialMatchDollar = TRUE ); + # Specify which linters to use... -linters <- lintr::linters_with_defaults( defaults = default_linters, +linters <- lintr::linters_with_defaults( # Check that no absolute paths are used: absolute_path_linter = lintr::absolute_path_linter(), @@ -52,9 +55,6 @@ linters <- lintr::linters_with_defaults( defaults = default_linters, # Allow commented code outside roxygen blocks: commented_code_linter = NULL, # lintr::commented_code_linter, - # Require the `[[` operator is used when extracting a single element from an object, not `[` (subsetting) or `$` (interactive use): - extraction_operator_linter = lintr::extraction_operator_linter(), - # Require that integers are explicitly typed using the form `1L` instead of `1`: implicit_integer_linter = lintr::implicit_integer_linter(), @@ -111,7 +111,7 @@ linters <- lintr::linters_with_defaults( defaults = default_linters, T_and_F_symbol_linter = lintr::T_and_F_symbol_linter(), # Report the use of undesirable functions (e.g., `attach` or `sapply`) and suggest an alternative: - undesirable_function_linter = lintr::undesirable_function_linter( fun = within( default_undesirable_functions, rm( options ) ) ), + undesirable_function_linter = lintr::undesirable_function_linter( fun = within( lintr::default_undesirable_functions, rm( options ) ) ), # Report the use of undesirable operators (e.g., `:::` or `<<-`) and suggest an alternative: undesirable_operator_linter = lintr::undesirable_operator_linter(),