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

cli_text sometimes omits interpolated fs variables #605

Closed
banbh opened this issue May 21, 2023 · 2 comments
Closed

cli_text sometimes omits interpolated fs variables #605

banbh opened this issue May 21, 2023 · 2 comments

Comments

@banbh
Copy link

banbh commented May 21, 2023

Sometimes (i.e., at random) cli_text seems to not print an interpolated variable of class fs_path if it is at the start of the string. For example, a typical output from one of the "BAD" examples below is shown below. Note that different runs result in different paths being omitted.

> purrr::walk(pp, \(p) cli_text('{p}.')) # BAD
January.
February.
.
April.
May.
.
July.
August.
September.
October.
.
December.

Examples:

# R version 4.3.0 (2023-04-21 ucrt)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 10 x64 (build 19044)
library(fs) # fs_1.6.1
library(cli) # cli_3.6.1

pp <- path(month.name) # arbitrary paths which don't exist

# BAD => occasionally `p` is omitted but the "." still appears
for (i in seq_along(pp)) cli_text('{pp[i]}.') # BAD
purrr::walk(pp, \(p) cli_text('{p}.')) # BAD
purrr::walk(pp, \(p) cli_text('{.emph {p}}.')) # BAD
purrr::walk(pp, \(p) cli_text('{p}', '.')) # BAD

# OK => nothing is omitted
purrr::walk(pp, \(p) cli_text('.{p}.')) # OK
purrr::walk(pp, \(p) cli_text('{.val {p}}.')) # OK
purrr::walk(pp, \(p) cli_alert_info('{p}.')) # OK
purrr::walk(pp, \(p) print(glue::glue('{p}.'))) # OK
purrr::walk(pp, \(p) cat(p, '.\n')) # OK
purrr::walk(as.character(pp), \(p) cli_text('{p}.')) # OK
@banbh
Copy link
Author

banbh commented May 23, 2023

I tried reproducing my own issue just now and failed. I'm not sure what has changed. Perhaps restarting RStudio (as opposed to merely restarting R) made a difference. Given that this may not be easily reproducible, perhaps it should be closed?

@olivroy
Copy link
Contributor

olivroy commented Aug 11, 2023

Don't know if it is related but in .run hyperlinks, if an argument is a fs::path, it causes issues..

library(fs)
library(cli)
path <- fs::file_create("x.R")
cli::cli_text("{.run fs::path_dir('{path}')}")
#> `fs::path_dir(''x.R'')`

# fixing requires converting to character
path_name <- as.character(path)
cli::cli_text("{.run fs::path_dir('{path_name}')}")
#> `fs::path_dir('x.R')`

fs::file_delete(path)

image

Created on 2023-08-11 with reprex v2.0.2

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

3 participants