roxygen doing thing I do not understand

Hello when I use rstudio (1.1.383 I am stuck on this version) and roxygens 6.1.1 and I try to build my package making sure NAMEPACE is generated by roxygen the following function:

#' Are all elements ox x elements in y
#' @export
#' @examples
#' all.in(x=c(1, 2), y=c(1, 3, 2)) #TRUE
#' all.in(x=c(NA, NULL), y=c(NA, NULL, 0)) #TRUE
#' all.in(x=c('a','b'), c('a','ab')) #FALSE
all.in <- function(x, y){
	return( all(x %in% y) )
}

is converted as the following in NAMESPACE
S3method(all,"in")

So it is fairly obvious that there is something going on with the all and in functions there but this is not what I want. Is there a way to tell roxygen2 to do the right thing ?

Not sure how to fix this, but the reason it's happening is because in R convention is to use dots for S3 methods, so roxygen assumes that what you are trying to do is to create a function called all for a class called in. You can avoid this with calling your function all_in, for example of a workaround.

1 Like

Hello, I do not think there is any instruction in the R manual that requires functions to use _ not dots.
As it is it looks like a bug in roxygen2 to me

Not sure what's your point here.

You've written that you don't understand why roxygen is doing what it's doing and I've explained why it's happening. You are right, there is no rule against using dots in function names, but generally it is considered (not by everyone, but by some) a bad practice for exactly the reason I've explained: you don't know in advance whether it's a name of a function or s3 method.

That being said, looks like SO has the solution for your problem that you can try - https://stackoverflow.com/questions/24594507/exporting-non-s3-methods-with-dots-in-the-name-using-roxygen2-v4#24607763

1 Like

It's not just Roxygen that will assume all.in is an S3 method. R will also assume that when there's an in class.

x <- c(TRUE, FALSE)
all(x)
# [1] FALSE

all.in <- function(x, y){
  return( all(x %in% y) )
}

class(x) <- "in"
all(x)
# Error in all.in(c(TRUE, FALSE), na.rm = FALSE) : 
#   unused argument (na.rm = FALSE)

In this specific case, there's little chance of something having the "in" class. But it's not guaranteed, and doing a find/replace to swap in _ seems easier than remembering a list of class names that'd break stuff.

Hello thanks for your answer, I knew I saw something once but could not find out where.
That will solve my issue.
With regards to my point, I think it was just miscommunication, I was just saying that "you should not be using dots" was not a good answer (I was not sure what you were suggesting)
Thanks

1 Like

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