Skip to content

Line break before function() provoke unexpected problem

Created by: pwaeckerle

Criteria of validation

The use of the following codes in a flat file do not affect the correct detection of the function real name :

  • linebreak, roxygen before
#' fake_name
real_name <- 
   function()
  • linebreak, comment before
#' fake_name
# a comment
real_name <- 
function()
  • comment between name and linebreak
#' fake_name
real_name <- # a comment
function()
  • commented line between name and linebreak
#' fake_name
real_name <- 
# a comment
function()
  • linebreak, nothing before
real_name <- 
   function()
  • no linebreak, comment before
#' fake_name
# a comment
real_name <- function()
  • no linebreak, code before
sqrt(1)
real_name <- function()
  • no linebreak, nothing before
real_name <- function()
  • linebreak, roxygen before, symbol "="
#' fake_name
real_name  =
   function()

Technical

Proposition 1 : detect the 1st assignment arrow in the code that is not in a comment or a roxygen Propostion 2 : combine the line above in paste(line_before, line). A line break turns into a space, and there is no risk of catching a different name


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.