4

I'm writing a package and if I run the code in my Rstudio it runs but when I give it to R CMD check to run, it doesn't recognize the S3 methods. I have a generic method:

count_kmers <- function(obj, klen = 6, parallel = TRUE, 
                    nproc = ifelse(parallel, comm.size(), 1), 
                    distributed = FALSE) {
                          UseMethod("count_kmers", obj)
                }

And then the substitute methods:

count_kmers.character <- function(obj, klen = 6, parallel = TRUE, 
                              nproc = ifelse(parallel, comm.size(), 1), 
                              distributed = FALSE) {...}
count_kmers.AAStringSet <- function(obj, klen = 6, parallel = TRUE, 
                                nproc = ifelse(parallel, comm.size(), 1), 
                                distributed = FALSE){...}

Now an example that I run in my documentation is:

seqs <- AAStringSet(c("seq1"="MLVVD",
                  "seq2"="PVVRA",
                  "seq3"="LVVR"))
## Count the kmers and generate a dataframe of the frequencies
freqs <- count_kmers(seqs, klen = 3, parallel = FALSE)
head(freqs)

If I run the code as a normal code it works but if I check it using R CMD check then it will complain:

Error in UseMethod("count_kmers", obj) : 
no applicable method for 'count_kmers' applied to an object of class "c('AAStringSet', 'XStringSet', 'XRawList', 'XVectorList', 'List', 'Vector', 'list_OR_List', 'Annotated')"

The AAStringSet is an object from the Biostrings package. But that doesn't matter, even if I pass a character string to count_kmers, I'm receiving the same error but saying:

no applicable method for 'count_kmers' applied to an object of class "character".
armen
  • 403
  • 5
  • 16
  • 2
    Are you sure you're loading the package in the script that R CMD is running? It's an easy mistake to load the package in R Studio but not the script, and would cause that exact error message. – jpd527 Feb 05 '18 at 20:51
  • 1
    Do you have the package code available somewhere, such as on GitHub? It's pretty hard to troubleshoot R CMD Check issues without taking a look at the package structure and code. – duckmayr Feb 06 '18 at 00:06
  • 1
    Are the generic and the methods in the same file? – F. Privé Feb 06 '18 at 07:21
  • 4
    Are both methods properly exported in the `NAMESPACE`? : ` export(count_kmers.character); export(count_kmers.AAStringSet); S3method(count_kmers, character); S3method(count_kmers, AAStringSet)` – Thomas Guillerme Feb 07 '18 at 06:00
  • @duckmayr yes it's on https://github.com/armenabnousi/naddaR – armen Feb 07 '18 at 20:06
  • @ThomasGuillerme I'm using roxygen2 for generation of NAMESPACE file. And it doesn't create those lines. But I changed my code to use the depreciated tag @ S3method and that added the lines to the NAMESPACE but CMD check ended up with the same errors. – armen Feb 07 '18 at 20:08
  • 1
    @jpd527 you mean the vignettes files? Yes, I have a library() at the beginning of the code in the vignettes. – armen Feb 07 '18 at 20:10
  • @F.Privé yes, I have only one file in the R/ directory and all methods are inside that. (I know it's better to break it up to multiple smaller files :) ). – armen Feb 07 '18 at 20:11
  • 1
    @ThomasGuillerme I think your answer was the closest/most helpful. I changed the NAMESPACE file without trying roxygen and it worked. I ended up changing the tags a bit and now using roxygen it builds too. Thank you all though – armen Feb 07 '18 at 21:25

0 Answers0