fusen icon indicating copy to clipboard operation
fusen copied to clipboard

Line break before function() provoke unexpected problem

Open pwaeckerle opened this issue 3 years ago • 1 comments

Problem description

When adding a line break between the affectation sign and the function keyword, fusen does not handle correctly the flat file content.

This line break can be added by the user, but more surely by the RStudio reformat shortcut.

fusen shows warning messages that alerts the user :

Updating mypkg documentation
ℹ Loading mypkg
Warning: [/home/rstudio/mypkg/R/my-function.R:8] @examples requires a value
Writing NAMESPACE
Writing NAMESPACE
Writing debug_fusen.Rd

In the output, the vignette is created as expected but the .R file has the name of the makdown title above the function description in the flat file.

Reprex

Working example

I use a minimal flat file with the following function description and example (no test) :

# My function

```{r function-debug_fusen}
#' debug_fusen
#'
#' @return 1
#' @export
#'
#' @examples
debug_fusen <- function() {
  1
}
debug_fusen()

When inflating, we have : a debug_fusen.R file in R\ and a vignette corresponding to the vignette_name attribute in the fusen::inflate() call.

Not working example

The same cas as below, with the simple addition of a line break before function :

# My function

```{r function-debug_fusen}
#' debug_fusen
#'
#' @return 1
#' @export
#'
#' @examples
debug_fusen <- 
  function() {
  1
}
debug_fusen()

When doing the inflate, we have :

  • Warning message (see above) regarding the absence of a function example,
  • The vignette updated (still well located thanks to the filename argument),
  • a my_function.R file created with no example in it.

pwaeckerle avatar Apr 21 '22 08:04 pwaeckerle

Problem: in R/inflate-utils.R, parsermd::rmd_node_code() splits code by reading line breaks (1 value = 1 line).

Proposal: add a new regex that would detect the pattern "<-" in "my_fun <- " and bind this value with the value returned by the regex regex_isfunction that detects the value " function() {"

FlorenceMounier avatar Sep 30 '22 10:09 FlorenceMounier

That should be good now.
Merged in: https://github.com/ThinkR-open/fusen/pull/186
Please tell us if your face again the problem

statnmap avatar Feb 19 '23 17:02 statnmap