Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help find docs duplicates #78

Open
maelle opened this issue Mar 22, 2018 · 2 comments
Open

Help find docs duplicates #78

maelle opened this issue Mar 22, 2018 · 2 comments

Comments

@maelle
Copy link
Contributor

maelle commented Mar 22, 2018

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:

  • Parse the results a bit more and say stuff like "the parameter BLABLA is documented in functions A, B, C" (and this even if the documentation is different, based on the parameter name rather than the whole line).

  • Also find lines that are close (in case one has two similar Details section but corrected a typo in only one of them?)

  • Have a verbose output but also markers?

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

@njtierney
Copy link

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
Copy link
Collaborator

hfrick commented Mar 25, 2018

Thanks both! I like this idea :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants