reprex_rtf() output has every line prefaced with "'

I'm wondering if anyone else has seen this behavior with the dev version of the reprex package and reprex_rtf():

(x <- rnorm(3))
#> [1] -0.5145298 -0.8394305  1.1100893
#> [1] -0.08129035

Created on 2020-09-20 by the reprex package (v0.3.0.9001)

The above was made with reprex(). So far so good. However, if I copy the same code and run reprex_rtf() on it, the resulting pasted output looks like this:

#' (x <- rnorm(3))
#' #> [1] 1.697790 -1.077479 1.061037
#' mean(x)
#' #> [1] 0.5604493

That is, every line is prefaced with a "' comment.

Output (rendered in HTML) sent to the Viewer in RStudio or a temporary HTML does not have additional #' characters inserted (though it's not syntax highlighted either).

I can run the equivalent highlight command from the command line, e.g.

highlight foo_reprex.R --out-format rtf --no-trailing-nl --encoding=UTF-8 --style moe --font-size 30 | pbcopy

and it works as expected. So I'm not sure where these comments characters are being inserted in the rendering process. I can't rule out of course that some idiosyncratic feature of my own R setup is responsible for this, but I can reproduce this issue with e.g. R --no-init-file and just a call to reprex::reprex_rtf().

Can anyone else can reproduce this behavior? If not I guess it's some weird problem of my own.


R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.6

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] knitr_1.29        magrittr_1.5      R6_2.4.1          rlang_0.4.7      
 [5] styler_1.3.2      highr_0.8         tools_4.0.2       xfun_0.17        
 [9] clipr_0.7.0       withr_2.2.0       htmltools_0.5.0   ellipsis_0.3.1   
[13] yaml_2.2.1        digest_0.6.25     tibble_3.0.3      lifecycle_0.2.0  
[17] crayon_1.3.4      processx_3.4.4    purrr_0.3.4       callr_3.4.4      
[21] vctrs_0.3.4       fs_1.5.0          ps_1.3.4          glue_1.4.2       
[25] evaluate_0.14     rmarkdown_2.3     reprex_0.3.0.9001 compiler_4.0.2   
[29] pillar_1.4.6      backports_1.1.10  pkgconfig_2.0.3  

Can you try to run this instead copy pasting ?

reprex::reprex_rtf(input = c("(x <- rnorm(3))", "mean(x)"))

This should give you the correct output. We will verify.

I'm afraid that doesn't work ... the pasted output is still prefaced with an #' on each line.

This needs further investigation but I can't reproduce it. But rtf does not work well on windows so I can't really test further. Maybe someone else will jump in.

Thanks for trying to follow up. Hopefully I can figure out what's happening here, as it more or less makes the excellent reprex_rtf() and prex_rtf() functions useless.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.