Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fuse does not work for quote #38

Closed
ben-schwen opened this issue Oct 19, 2024 · 3 comments
Closed

fuse does not work for quote #38

ben-schwen opened this issue Oct 19, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@ben-schwen
Copy link

ben-schwen commented Oct 19, 2024

Hey! Thanks for the great package. So far, it's quite nice to use!

We are trying to switch from rendering our vignettes with markdown and knitr to litedown.

This seems to work fine for most of our vignette except for the programming one where it fails at
https://github.com/Rdatatable/data.table/blob/200d6572b4687f3bfd555d933b0de4272f885eab/vignettes/datatable-programming.Rmd#L133-L138

Below also a reprex:

litedown::fuse('x<-1;quote(x)')
# <pre><code class="language-r">x&lt;-1;quote(x)
# </code></pre>
# <pre><code>#&gt; [1] 1
# </code></pre
litedown::fuse('quote(x)')
# Error in (function (x, ...)  : object 'x' not found

OT: is there an option to render tables with fuse like below? I couldn't come up with the right option from reactor()...

iris
#      Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
#             <num>       <num>        <num>       <num>    <fctr>
#   1:          5.1         3.5          1.4         0.2    setosa
#   2:          4.9         3.0          1.4         0.2    setosa
#   3:          4.7         3.2          1.3         0.2    setosa
#   4:          4.6         3.1          1.5         0.2    setosa
#   5:          5.0         3.6          1.4         0.2    setosa
# ---
# 146:          6.7         3.0          5.2         2.3 virginica
# 147:          6.3         2.5          5.0         1.9 virginica
# 148:          6.5         3.0          5.2         2.0 virginica
# 149:          6.2         3.4          5.4         2.3 virginica
# 150:          5.9         3.0          5.1         1.8 virginica
@yihui yihui added the bug Something isn't working label Oct 20, 2024
@yihui
Copy link
Owner

yihui commented Oct 20, 2024

This is a bug in the xfun::record(). Fixed in the dev version of xfun now. Thanks for the report!

OT: is there an option to render tables with fuse like below? I couldn't come up with the right option from reactor()...

For now, there isn't. fuse()'s default behavior is to print at most 10 rows by default (as a Markdown table). It doesn't print out the mode/class of each column below the column header, though.

  • If you want the exact printing behavior of data.table:::print.data.table and want the result to be a table, you can register an S3 method on xfun::record_print (data.table doesn't have to import xfun).
  • If you only want console output and not a table, you can bypass the table via
    ```{r, print=xfun:::record_print.default}
    data.table::as.data.table(iris)
    ```
    

@ben-schwen
Copy link
Author

Thanks for the quick response and the fix!

@yihui
Copy link
Owner

yihui commented Oct 31, 2024

FYI the new version of xfun is on CRAN now.

clrpackages pushed a commit to clearlinux-pkgs/R-xfun that referenced this issue Nov 18, 2024
Michael Chirico (1):
      Remove unused function (#93)

Yihui Xie (16):
      start the next version
      add argument use_block = FALSE to protect_math()
      no need to escape " by default in html_escape()
      add a `start` argument to make_fence()
      ignore $ $ as inline math if backticks appear after opening $ or before closing $
      fix yihui/litedown#34: allow () around math expressions (outside dollar signs)
      only check `^<pre>` and `</pre>$`
      read_all()'s `before` and `after` functions can take the file content as the second argument
      tried an implementation of prose_index() via commonmark but it's too slow; leave the code here for future reference
      stop early if graphics device failed to open, e.g. png(type = 'cairo') can fail on macOS without xquartz, but it doesn't throw an error, so we have to check if dev.list() really has a new device
      fix yihui/litedown#38: for `name` and `call` values (typically from quote(), but could be from as.name() or call(), too), use do.call(quote = TRUE) in reocrd()
      forgot to suggest commonmark in aa75d8fb04d0637dbfccca0d3b6aa0c1e5108799
      try dev version of litedown
      close yihui/litedown#37: provide a helper function to clean up apps registered in tools:::.httpd.handlers.env
      amend 6b98bb6b05f8ff7c586057174ee093e2b2ea5231: knitr has tests that expect `"` to be converted to `&quot;`
      CRAN release v0.49
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jan 12, 2025
# CHANGES IN xfun VERSION 0.50

- The function `isFALSE()` has been removed from this package. The
  deprecation notice was given two years ago:
  https://yihui.org/en/2023/02/xfun-isfalse/

- Added a new function `tabset()` to represent a list with a
  tabset. The representation is similar to `str()`, but uses a visual
  form.

- Factored out the function `taml_load()` and exported it (TAML is a
  tiny subset of YAML). Also added a new function `taml_save()` to
  convert simple lists to YAML.

- The `print` argument of `record()` can accept non-function values
  now, in which case `print()` (or `show()` for S4 objects) will be
  used as the print function.

- The `record()` results can also be formatted to Markdown via
  `format(record(), to = 'markdown')`.

- Moved `knitr::combine_words()` into this package as
  `xfun::join_words()`. The former has become a simple wrapper of the
  latter.

- Similarly, moved `knitr::write_bib()` into this package as
  `xfun::pkg_bib()`.

- Moved the internal function `str_wrap()` from **knitr** and exported
  it as `xfun::str_wrap()`.

- Exported the internal `find_globals()` and `find_locals()`
  functions.

- `md_table()` escapes `|` in the table to `\|` instead of `&#124;`
  now.

- `yaml_load(use_yaml = FALSE)` allows for indenting sub-fields by any
  number of spaces now (thanks, @J-Moravec, #95). Previously, one
  level of indentation must use exactly 2 spaces.

- `divide_chunk()` no longer requires every line of chunk options to
  be commented out when the engine uses a pair of comment delimiters
  (such as `/*` and `*/` for CSS) instead of a single comment
  character. It suffices to use the opening delimiter at the beginning
  and closing delimiter at the end, e.g.,

  ````md
  ```{css}
  /*| echo=FALSE,
      label='foo' */
  ```
  ````

  Previously, every line must be commented out like:

  ````md
  ```{css}
  /*| echo=FALSE, */
  /*| label='foo' */
  ```
  ````

# CHANGES IN xfun VERSION 0.49

- Added an argument `use_block = FALSE` to `protect_math()`. When
  `use_block = TRUE`, a `$$ $$` expression that spans across multiple
  lines will be protected in a code block.

- `protect_math()` will ignore `$ $` if there are backticks after the
  opening `$` or before the closing `$`, e.g., ``$`this is not
  math`$``.

- `protect_math()` allows for parentheses `()` around math expressions
  now, e.g., `($x$)` was previously not recognized but is recognized
  now (thanks, @AlbertLei, yihui/litedown#34).

- `record()` works with `quote()` now (thanks, @ben-schwen,
  yihui/litedown#38).

- `html_escape()` will not escape double quotes (i.e., convert `"`" to
  `&quot;`) by default, and the conversion will be done only for
  `html_escape(attr = TRUE)`.

- The arguments `before` and `after` of `read_all()` can take
  functions of two arguments now, with the second argument being the
  content of each file.

- Added an argument `start` to `make_fence()`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants