Is it common/acceptable to use getRversion()
in packages and to only load certain functions depending on the version of R the user has.
I am writing a package that uses the deparse1()
and str2lang()
functions. deparse1()
is from R 4.0.0
and str2lang()
is from R 3.6.0
. I have included a bit of code to include these functions if the user is using an older version of R:
if(getRversion() < "4.0") {
deparse1 <- function(expr, collapse = " ", width.cutoff = 500L, ...)
paste(deparse(expr, width.cutoff, ...), collapse = collapse)
}
if(getRversion() < "3.6"){
str2lang <- function(s) parse(text = s, keep.source=FALSE)[[1]]
}
The definition for deparse1()
is exact, however str2lang()
uses an Internal function, but the documentation says it does roughly this (with a few additional checks)
It has passed check()
on my system, so including these lines of code (which don't run) is not "illegal" as far as R CMD CHECK
is concerned.
Has anyone seen this kind of thing done elsewhere? I know that some packages do this inside of functions, but this is not within a function, and is just in my R/
folder