[R-pkg-devel] Overriding + operator in a package

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Sat Mar 21 20:23:01 CET 2020


On 21/03/2020 3:03 p.m., Emanuele Cordano wrote:
> Dear list,
> 
> I just released on my Github account the following R package:
> https://github.com/ecor/stringplus
> containing an override of '+' arithmetic operator in order to sum two
> strings as follows:
> 
> ```
> 
> library(stringplus)
> 
> subject <- "Susan"
>       verb <- "is eating"
>       object <- "an apple"
> 
>       out <- subject+" "+verb+" "+object
> 
>       dir <- "~/mydrir/"
>       files <- c("myfile.txt","readme.txt")
> 
> 
> ```
> I would like to submit "stringplus"  to CRAN but while ckecking I found out
> the following warning:
> 
> * checking S3 generic/method consistency ... WARNING
> Warning: declared S3 method '+.character' not found
> Warning: declared S3 method '+.default' not found
> See section ‘Generic functions and methods’ in the ‘Writing R
> Extensions’ manual.
> 
> R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
> 
> I wrote the method in S3. I checked the section ‘Generic functions and
> methods’ in the ‘Writing R' (R-release) Extensions’ manual but I did not
> find a clear (to me) example or explanation  for arithmetic (or base)
> operators.
> Do you suggest how to solve this warning?

I suspect the problem is that you created a new `+` generic function. 
There's already an internal one of those in the base package; you 
shouldn't create a new one.

There are other errors in your Github code; presumably you have local 
changes that need to be committed and pushed there.

Duncan Murdoch



More information about the R-package-devel mailing list