Skip to content
2 changes: 1 addition & 1 deletion .github/workflows/lint_changed_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint_random_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ options( digits = 16L );
#' main();
main <- function() {
# Define benchmark parameters:
name <- "abs";
name <- 'abs';
iterations <- 1000000L;
repeats <- 3L;

Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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).
#'
Expand All @@ -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:
Expand All @@ -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 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ options( digits = 16L );
#' main();
main <- function() {
# Define benchmark parameters:
name <- "abs";
name <- 'abs';
iterations <- 1000000L;
repeats <- 3L;

Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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).
#'
Expand All @@ -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:
Expand All @@ -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 );
}
Expand Down
12 changes: 6 additions & 6 deletions tools/lint/r/linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand All @@ -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(),

Expand All @@ -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(),

Expand Down Expand Up @@ -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(),
Expand Down
Loading