r-lib / roxygen2

Generate R package documentation from inline R comments
https://roxygen2.r-lib.org
Other
584 stars 231 forks source link

@examplesIf results in extra interline space between "Examples" section title and examples code #1256

Open ramiromagno opened 2 years ago

ramiromagno commented 2 years ago
#' @examplesIf
#' # Open in PGS scores Catalog Web Graphical User Interface
#' open_in_pgs_catalog(c('PGS000001', 'PGS000002'))
#'
#' # Open PGS Catalog Publications
#' open_in_pgs_catalog(c('PGP000001', 'PGP000002'),
#'   pgs_catalog_entity = 'pgp')
#'
#' # Open Sample Sets (PSS)
#' open_in_pgs_catalog(c('PSS000001', 'PSS000002'),
#'   pgs_catalog_entity = 'pss')
#'
#' # Open EFO traits (EFO)
#' open_in_pgs_catalog(c('EFO_0001645', 'MONDO_0007254'),
#'   pgs_catalog_entity = 'efo')
#'
#' @export

results in:

snap2

gaborcsardi commented 2 years ago

Yes, it generates this:

\examples{
\dontshow{if () (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
# Open in PGS scores Catalog Web Graphical User Interface
open_in_pgs_catalog(c('PGS000001', 'PGS000002'))
...
open_in_pgs_catalog(c('EFO_0001645', 'MONDO_0007254'),
  pgs_catalog_entity = 'efo')
\dontshow{\}) # examplesIf}
}

and \dontshow{} will insert an empty line, and it probably should not.

We can change it to generate this:

\examples{
\dontshow{if () (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}# Open in PGS scores Catalog Web Graphical User Interface
open_in_pgs_catalog(c('PGS000001', 'PGS000002'))
...
open_in_pgs_catalog(c('EFO_0001645', 'MONDO_0007254'),
  pgs_catalog_entity = 'efo')\dontshow{\}) # examplesIf}
}

I didn't do that in case the \dontshow{} behavior should change in the future, and then we might generate syntactically invalid code. But I guess we will notice that anyway, so I don't mind changing it.