roxygen export conditional on R version

I need to add something like this so functions are only exported for specific R versions:

  if(getRversion() < "4.5.0") {
    S3method(head, ts)
    S3method(tail, ts)

Any idea how to do this in roxygen?

1 Like

Does this help?

"you can use @rawNamespace code which inserts code literally into the NAMESPACE. This is useful if you need a conditional import or export, e.g.

From backports:
#' @rawNamespace if (getRversion() < "4.0.0") export(stopifnot)

If you need to automate this, @evalNamespace fun() will evaluate fun() in the package environment and insert the results into NAMESPACE"

Source: Managing imports and exports • roxygen2



@robjhyndman thanks for all your work. This would be my approach:

robjhyndmanFunc <- function(){
  if(getRversion() < "4.5.0") {

#' Title
#' @eval robjhyndmanFunc()
hello <- function() {
  print("Hello, world!")

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.