rstudio/vetiver-r

Find a better solution for generating code in `vetiver_write_plumber()`

Opened this issue · 0 comments

As of right now, we use this approach to generating the code to read a board in vetiver_write_plumber():

## rlang::expr_deparse won't work for board_url, but
## base deparse won't work for S3 and other complex boards:
if (inherits(board, "pins_board_url")) {
board <- deparse(pins::board_deparse(board))
} else {
board <- rlang::expr_deparse(pins::board_deparse(board))
}

Problems around this have come up multiple times, in #253, #256, and #239, but we still are not in a good place. @EmilHvitfeldt reported yet another problem, when the code needed for board_*() is so long that the width option makes it break across lines.

What is a good way to solve this once and for all?

  • Is there something like deparse() or rlang::expr_deparse() that lets us never print across multiple lines?
  • Just set width to something really big?
  • Can we get the numbers of characters from pins::board_deparse(board) and then set the width in rlang::expr_deparse()? (Note, it's not a character.) Like sum(nchar(as.character(board_deparse(board)))) and then add in another couple dozen characters to account for how the call is structured?