I am struggling with the documentation of an R6 class and its methods. My goal is to get the autocompletion in RStudio for the methods. At the moment, I only get the name of the method but no the help information I normally get using roxygen2 documenting a function with parameters etc.
At the moment, this is my class:
#' @importFrom R6 R6Class
MQParameters <- R6::R6Class(
'MQParameters',
public=list(
initialize=function(file_path=NA) {
private$location <- file_path
mq_parameters <- read.delim(file_path, stringsAsFactors=FALSE)
mq_parameters <-
setNames(mq_parameters$Value, mq_parameters$Parameter)
private$mq_version <- unname(mq_parameters['Version'])
private$fasta_file <-
gsub('\\\\', '/', strsplit(mq_parameters['Fasta file'], ';')[[1]])
},
# this method returns the version
getVersion=function() {
private$mq_version
},
# this methods returns the fastafile.
# @param new_param it is possible to rewrite the basedir.
getFastaFile=function(new_basedir=NA) {
if(is.na(new_basedir)) {
private$fasta_file
} else {
file.path(new_basedir, basename(private$fasta_file))
}
}
),
private=list(
location=NULL,
mq_version=NULL,
fasta_file=NULL
)
)
If you are interested to test this class, here is a little reproducible example:
df <- data.frame(Parameter=c('Version', 'Fasta file'),
Value=c('1.5.2.8','c:\\a\\b.fasta'))
write.table(df, 'jnk.txt', sep='\t', row.names=F)
p <- MQParameters$new('jnk.txt')
p$getVersion()
# [1] "1.5.2.8"
p$getFastaFile()
# [1] "c:/a/b.fasta"
p$getFastaFile(new_basedir='.')
# [1] "./b.fasta"
I don't know how to document parameters, because the parameters are actually belong to the creator but not to the class. What about the parameters to other methods within the function?
What is the preferred way to document a class with it's methods?
I would love to get the "normal" functionality from RStudio, like hitting F1 to get directly to the help page.
By searching the internet, I saw already some reports on Github about this topic, but they more than a year old.
Update
Thanks to the answer of mikeck I now have a nice documentation for the class and it's methods. But what I am still lacking is the possibility to get the hint of function/method and its arguments like in this screenshot for a common function:
I am wondering if I can somehow register my function manually, but since it doesn't have a specific name (it is always coupled with the variable objectname you use for the object OBJECTNAME$methodeCall()) I don't know how to do this.
