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
#', 2), y=c(1, 3, 2)) #TRUE
#', NULL), y=c(NA, NULL, 0)) #TRUE
#''a','b'), c('a','ab')) #FALSE <- function(x, y){
	return( all(x %in% y) )

is converted as the following in NAMESPACE

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 -

1 Like

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

x <- c(TRUE, FALSE)
# [1] FALSE <- function(x, y){
  return( all(x %in% y) )

class(x) <- "in"
# Error in, 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)

1 Like

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