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

Disable urls during Rmarkdown::render() in RStudio? #581

Closed
hadley opened this issue Feb 8, 2023 · 13 comments
Closed

Disable urls during Rmarkdown::render() in RStudio? #581

hadley opened this issue Feb 8, 2023 · 13 comments

Comments

@hadley
Copy link
Member

hadley commented Feb 8, 2023

e.g. create an .Rmd containing this code and render it with cmd + shift + K

```{r}
cli::cli_abort("{.url https://posit.co}")
```

The issues panes doesn't support ANSI formatting:

Screenshot 2023-02-08 at 12 54 52

OTOH the output pane does:

Screenshot 2023-02-08 at 12 55 14

@gaborcsardi
Copy link
Member

Since the same output goes to both places we can either have no links anywhere, or maybe we can add links support to the issues panel, or at least make the issue panel drop ANSI sequences?

@hadley
Copy link
Member Author

hadley commented Feb 8, 2023

I think no links might be the safer choice.

@mikeroswell
Copy link

Glad this is on the radar! yihui/knitr#2234 (comment)

@cderv
Copy link

cderv commented Feb 27, 2023

@mikeroswell beat me to it while I was writing this message. Here it is anyway

We have an occurence of this in yihui/knitr#2234 with dplyr deprecation warnings as lifecycle is using urls now in the deprecation message

For HTML outputs, it just show undesired character in the message, but for PDF, it prevents rendering because of those unknown special characters still present.

@hadley
Copy link
Member Author

hadley commented Mar 1, 2023

Looking at the issue from knitr, that might be actually be a different problem? Because there the escapes are appearing in the document.

@gaborcsardi
Copy link
Member

I think they should be the same, the R process that runs knitr runs "in the render pane", so hyperlinks were turned on. Now they are off.

@hadley
Copy link
Member Author

hadley commented Mar 1, 2023

I thought we used different heuristics inside an Rmd, but maybe I'm imagining that?

@gaborcsardi
Copy link
Member

We are doing that for colors, yeah. Probably the simplest is that if there are no colors, then we also turn off the hyperlinks.

@pg320
Copy link

pg320 commented Mar 3, 2023

Any news on a fix for this? Compile (R/Rmarkdown) document to PDF currently won't run because of the unicode characters.

@gaborcsardi
Copy link
Member

gaborcsardi commented Mar 3, 2023

It is already fixed. If you still have issues, make sure you use cli from this repository. You can also turn off links by setting the cli.hyperlink option to FALSE or the R_CLI_HYPERLINKS environment variable to false.

@pg320
Copy link

pg320 commented Mar 6, 2023

Could you guide me on installing the package from GitHub? I've tried using the devtools and remotes package, but they fail as cli is already in ise

@gaborcsardi
Copy link
Member

gaborcsardi commented Mar 6, 2023

Try this:

install.packages("pak", repos = sprintf(
  "https://r-lib.github.io/p/pak/stable/%s/%s/%s",
  .Platform$pkgType,
  R.Version()$os,
  R.Version()$arch
))
pak::pkg_install("r-lib/cli")

@jennybc
Copy link
Member

jennybc commented Mar 23, 2023

Just to add more color, the change motivated by this seems to have also fixed a problem in devtools::build_rmd(), where I was seeing ANSI escapes in the rendered product.

jrwishart pushed a commit to Displayr/cli that referenced this issue Oct 25, 2023
* Fix docs: remove duplicated item

* Fix typos

* Fix another typo

* Fix typo

* Add UTF-8 snapshot output

For a tests with utf-8/ascii variants.

* document()

* Update GHA

* New keypress() function (r-lib#540)

* New `hash_file_md5()` function, MD5 hash of files

* No show-cursor ANSI seq in task cb & finalizer if env var

If `R_CLI_HIDE_CURSOR` is set to `false` then cli does not
register a task callback and a finalizer to show the cursor.
This is to make the output more predictable in test cases.

* Compatibility with webR

* Support hidden visibility

* README in light/dark mode (r-lib#546)

* add prettyunits to `Config/Needs/website` (r-lib#549)

Closes r-lib#548

* Polish NEWS

[ci skip]

* Fix URL redirect

[ci skip]

* Increment version number to 3.5.0

* Increment version number to 3.5.0.9000

* Fix doc (r-lib#552)

* hash_*sha1() functions to calculate SHA-1 hashes (r-lib#551)

* Set empty param-lists to `void` in exported `progress.h` file (r-lib#553)

* The progressr progress handler now reports progress correctly

Closes r-lib#558.

* Refine progress bar condition

Show after `getOption("cli.progress_show_after", 2)/2` if
we are less than half way.

Closes r-lib#542.

* format_inline() now keeps newline charaters

* New `keep_newlines = TRUE` argument to `format_inline()`

It does not break any tests, but we might need to change the
default to `FALSE` if it breaks reverse dependencies.

* Add test cases for `format_inline(..., keep_newlines)`

* Add more (void) args to pacify CRAN's compilers

* `format_inline()` now keeps all whitespace as is by default

And has a new argument: `keep_whitespace` to choose the old
behavior.

* Increment version number to 3.6.0

* Increment version number to 3.6.0.9000

* Fix ASAN warnings

Closes r-lib#565.

* Fix/tweak documentation

* Update errors.R from processx

* Manual: link to [inline-markup] where appropriate

Closes r-lib#585.

* Fix hyperlink support detection in RStudio

The RSTUDIO_CLI_HYPERLINKS env var should only be
used if we are in a pane with hyperlink support.

* Turn off hyperlinks in the RStudio render pane

Closes r-lib#581.

* Remove test case that is not needed any more

* Turn off ANSI hyperlinks if we don't have ANSI colors

If we don't have colors, then we probably don't have
hyperlink support, either.

* Fix test cases for hyperlink detection changes

* Update NEWS

* Fix snapshots

* Increment version number to 3.6.1

* 'lengths' instead of 'length'

* Document `str` in the class list

* Mention `encodeString()`

* Increment version number to 3.6.1.9000

* Fix pkgdown build on CI

* Fix typo in "directory"

* Tyoi

* Add R-hub v2 workflow file

[ci skip]

* Fixed typo

* Fix minor typo in hash_raw_animal docs

* Fixed typo in hash_animal() docs

* Update hash.R

Fixed typo in hash_sha1() docs

* Fixed a few typos in hash_md5() docs

* Replaced between to remove ambiguitity about whether range is inclusive

* Update hash.R

Fixed minor typo in hash_sha256() docs

* Add  missing c() in cli_abort()

* Move scripts to /exec

* Fix URLs in news.R script

* Fix typo

* Redocument

* Change semantics of cli.default_num_colors option

So that it is possible to use it even if color support is not
detected, but at least it is not ruled out by some other
options and detections.

* Document

[ci skip]

* Docs typo

[ci skip]

* DS-5106: Rerun GitHub Action

* Trigger tests

---------

Co-authored-by: David C Hall <davidchall@users.noreply.github.com>
Co-authored-by: Gábor Csárdi <csardi.gabor@gmail.com>
Co-authored-by: Salim B <git@salim.space>
Co-authored-by: George Stagg <george.stagg@rstudio.com>
Co-authored-by: Lionel Henry <lionel.hry@gmail.com>
Co-authored-by: Simon P. Couch <simonpatrickcouch@gmail.com>
Co-authored-by: Jenny Bryan <jenny.f.bryan@gmail.com>
Co-authored-by: DavisVaughan <davis@rstudio.com>
Co-authored-by: James Baird <j.baird94@gmail.com>
Co-authored-by: olivroy <52606734+olivroy@users.noreply.github.com>
Co-authored-by: Shian Su <contact.shian.su+github@gmail.com>
Co-authored-by: Justin Mills <justin_mills@fws.gov>
Co-authored-by: we <we@email.com>
Co-authored-by: jrwishart <opensource@displayr.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants