
Add Explicit Integer Suffix L to Integer Literals
Source: R/20A_package_convert_int_literals.R, R/20_convert_int_literals.R
convert_int_literals.RdConverts bare integer literals to explicit integer form with an L suffix,
e.g. seq_len(10) becomes seq_len(10L). Strings and comments are left
unchanged.
convert_int_literals() operates on one R file. When path is NULL and
RStudio is available, it uses the currently active document.
package_convert_int_literals() walks selected directories of an R package
and applies the same conversion to every .R / .r file found, except
files generated by Rcpp::compileAttributes() or rextendr::document()
(see exclude).
Arguments
- path
For
convert_int_literals(), a character string specifying the R file to modify. IfNULLand RStudio is available, the currently active document path is used.For
package_convert_int_literals(), a character string specifying the package root. IfNULL, the current working directory is used.- dirs
Character vector of subdirectories relative to
pathto search. Used only bypackage_convert_int_literals(). Defaults toc("R").- recursive
Logical; recurse into subdirectories. Used only by
package_convert_int_literals(). DefaultTRUE.- exclude
Character vector of file names to skip, matched case-insensitively against the file base name. Used only by
package_convert_int_literals(). Defaults to the auto-generated wrapper filesc("RcppExports.R", "extendr-wrappers.R"). UseNULL(orcharacter()) to process all files.- ...
Additional arguments. Currently unused and must be empty.
- verbose
Logical; enable or disable per-file messages. Used only by
convert_int_literals(). DefaultTRUE.
Value
convert_int_literals() invisibly returns the modified file path.
package_convert_int_literals() invisibly returns a character vector of
modified file paths.
Details
A token is treated as an integer literal when it is:
a decimal integer (
10,0,-is not part of the token), ora hexadecimal integer (
0xFF,0X10),
and it is not:
already suffixed with
L/l,a floating-point number (
10.,1.0,.5),scientific notation, including a signed exponent (
1e5,1e-3,1E-3),a complex literal (
10i),adjacent to an identifier character (
a-zA-Z0-9._).
Examples
if (FALSE) { # \dontrun{
# --- Single file ---
temp <- tempfile(fileext = ".R")
writeLines("tmp <- seq_len(10)", temp)
convert_int_literals(temp)
readLines(temp)
# "tmp <- seq_len(10L)"
# --- Entire package ---
tmp_pkg <- tempdir()
usethis::create_package(tmp_pkg, open = FALSE)
writeLines("foo <- seq_len(42)", file.path(tmp_pkg, "R/foo.R"))
package_convert_int_literals(tmp_pkg)
readLines(file.path(tmp_pkg, "R/foo.R"))
} # }