gluedown icon indicating copy to clipboard operation
gluedown copied to clipboard

option like `na.rm = TRUE`

Open balthasars opened this issue 4 years ago • 2 comments

Hi there!

I wanted to ask if there is a way for NAs not to occur in the output of the md_-functions, similar to the na.rm = TRUE option in sum() and other similar functions, such that the following doesn't occur:

library(gluedown)
one <- c("one", "two", NA)
md_bullet(one)
#> * one
#> * two
#> * NA

Created on 2021-04-02 by the reprex package (v1.0.0)

All the best and thanks for the package

balthasars avatar Apr 02 '21 18:04 balthasars

There isn't a way as of right now, but it could be added. I'll have to think about whether or not it should be an argument and look at some examples of how other packages handle it. You could always call md_bullet(na.omit(one)).

k5cents avatar Apr 02 '21 18:04 k5cents

NA values could potentially be treated like "empty" list elements.

md_bullet <- function(x, marker = c("*", "-", "+")) {
  marker <- match.arg(marker)
  x[is.na(x)] <- ""
  glue::glue("{marker} {x}")
}
md_bullet(x = c(1, NA, 2))
  • 1
  • 2

Created on 2021-04-13 by the reprex package (v1.0.0)

k5cents avatar Apr 13 '21 14:04 k5cents