ropensci-review-tools / goodpractice

Advice on R Package Building
https://docs.ropensci.org/goodpractice/
Other
465 stars 37 forks source link

Help find docs duplicates #78

Open maelle opened 6 years ago

maelle commented 6 years ago

This is a feature request dear @hfrick πŸ™ 😺

With roxygen2 one can inherit parameters/sections from one function to the other in order to remove duplication of doc sources while still having docs everywhere it's needed. Cf this blog post. I think a function that'd help find duplicates could be useful.

Here is code by @jimhester to find duplicates

files <- Sys.glob(paths = "R/*R")
lines <- grep("#'", unlist(lapply(files, readLines)), value = TRUE)
unique(lines[duplicated(lines)])

He also wrote the tidyverse-compliant version

library(tidyverse)
fs::dir_ls("R", glob = "*R") %>%
  map(read_lines) %>%
  flatten_chr() %>%
  str_match("#'.*") %>%
  keep(duplicated(.)) %>%
  unique()

This already helps a lot. A perfect helper would:

I also wonder if a similar tool for code lines could be useful but maybe it even already exists? πŸ€”

njtierney commented 6 years ago

Perhaps the output could also describe how to address duplication, e.g.,

An alternative to @describeIn is @rdname. It overrides the default file name generated by roxygen and merges documentation for multiple objects into one file. This gives you complete freedom to combine documentation however you see fit. There are two ways to use @rdname. You can add documentation to an existing function:

#' Basic arithmetic
#'
#' @param x,y numeric vectors.
add <- function(x, y) x + y

#' @rdname add
times <- function(x, y) x * y

taken from https://cran.r-project.org/web/packages/roxygen2/vignettes/rd.html

I also second the idea of finding duplicated code lines! That'd be seriously handy for refactoring code.

hfrick commented 6 years ago

Thanks both! I like this idea :)