Search code examples
rdevtoolsr-packageroxygen2

Data package-r documentation


I am creating a package and the automatic generation of Rd file for documentation work well with Roxygen2 for my function (here is an example of my R file which gives a good Rd file using roxygen2::roxygenise():

#' Total flows of a DF
#'
#' This function allows you to store the totals of origins, destinations and internal flows for each city in a dataframe,
#' from a long format matrix of flows.
#'
#' @param tabflows A data.frame of flows between origins and destinations (long format matrix containing, at least, origins, destinations, flows)
#' @param idori identifiant ori
#' @param iddes identifiant des
#' @param idflow identifiant flux
#' @return A data.frame of totals origins, destinations and internals flows for each city
#'
#' @examples
#' data(tabflows)
#'
#' popTab <- pop_tab(tabflows = tabflows, idori = "ORI", iddes = "DES", idflow = "FLOW")
#'
#' popTab[10:10,]
#'
#' @export
#' @importFrom stats aggregate

pop_tab <- function(tabflows, idori, iddes, idflow){
  tabflowIntra <- tabflows[tabflows[idori] == tabflows[iddes], ]
  tabflowIntra <- aggregate(x = tabflowIntra[[idflow]], by = list(tabflowIntra[[idori]],tabflowIntra[[iddes]]), FUN = sum)
  colnames(tabflowIntra) <- c("ORI", "DES","TOTINTRA")
  tabflowOri <- tabflows[tabflows[idori] != tabflows[iddes], ]
  tabflowOri <- aggregate(x = tabflowOri[[idflow]], by = list(tabflowOri[[idori]]), FUN = sum)
  colnames(tabflowOri) <- c("ORI","TOTORI")
  tabflowDes <- tabflows[tabflows[idori] != tabflows[iddes], ]
  tabflowDes <- aggregate(x = tabflowDes[[idflow]], by = list(tabflowDes[[iddes]]), FUN = sum)
  colnames(tabflowDes) <- c("DES","TOTDES")
  poptab <- merge(x = tabflowIntra, y = tabflowOri, by.x = idori, by.y =idori)
  poptab <- merge(x = poptab, y = tabflowDes, by.x = idori, by.y =iddes)
  poptab[[iddes]] <- NULL
  colnames(poptab) <- c("idflow", "TOTINTRA","TOTORI", "TOTDES")
  return(poptab)
}

However, when I try to roxygenise() this next R file which is about data documentation, no Rd file is generated in the man directory. I could of course write the Rd file myself but I would like to know what is the issue here...

#' @title Commuters
#' @name tabflows
#' @description Data on commuters between Urban Areas in Paris region in 2014.
#' Fields: \cr
#' \itemize{
#' \item{ORI: Code of the urban area of residence}
#' \item{DES: Code of the urban area of work}
#' \item{MODE: Transport mode used by the workers}
#' \item{FLOW: Number of commuters between i and j}
#' \item{DIST: distance between the urban area of work and the urban area of residence}
#' \item{DISTTOT: total distance between the urban area of work and the urban area of residence}
#' \item{ORILIB: Name of the urban area of residence}
#' \item{DESLIB: Name of the urban area of work}
#' }
#' @docType data
#' @examples
#' ## tabflows
#' data(tabflows)

Solution

  • Write NULL after the last line:

    ......
    #' @examples
    #' ## tabflows
    #' data(tabflows)
    NULL