openpharma / roxytypes

typed parameter definitions for `roxygen2`
https://openpharma.github.io/roxytypes/
Other
5 stars 1 forks source link

Feature: migration tools #3

Closed dgkf closed 1 year ago

dgkf commented 1 year ago

It would be nice if roxytypes provided migration tools. Just brainstorming what the initial user-facing api might look like, I think something like this would be good:

Default behavior:

Replace all @params with @typed, leaving a blank entry for the type definition.

convert_params()

Resulting in the following changes:

- #' @param var this is the description
+ #' @typed var:
+ #'   this is the description

This will still throw warnings due to all the missing types when you try to document the package, but this is a necessary part of migration.

Pattern matched conversion:

To fine-tune a migration, provide a regular expression to match on the current parameter definitions. If it matches, use the extracted type and description. Otherwise, use another parameter to decide what to do with descriptions that fail to match. Either keep as @param or convert to @typed with a missing type definition.

convert_params(fmt = r"(\(`(?<type>)`\)(?<description>))", unmatched = TRUE) 

Resulting in the following changes:

- #' @param var (`my type`) this is the description
+ #' @typed var: my type
+ #'   this is the description
- #' @param var2 this is an unmatched description
+ #' @typed var2:
+ #'   this is an unmatched description

Other considerations

danielinteractive commented 1 year ago

Cool, the pattern matched conversion will be super useful :-) I guess based on a branch here I could try this out on a larger package and give feedback.

dgkf commented 1 year ago

Done! (forgot to mark as closed in the PR)