yihui / xfun

Miscellaneous R functions
https://yihui.org/xfun/
Other
141 stars 28 forks source link

`reprex::reprex(xfun::session_info("knitr"))` 输出结果不显示 RStudio 版本信息 #62

Closed chuxinyuan closed 2 years ago

chuxinyuan commented 2 years ago

xfun::session_info("knitr") 输出结果如下:

R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.3 LTS, RStudio 1.4.1717

Locale:
  LC_CTYPE=zh_CN.UTF-8       LC_NUMERIC=C              
  LC_TIME=zh_CN.UTF-8        LC_COLLATE=zh_CN.UTF-8    
  LC_MONETARY=zh_CN.UTF-8    LC_MESSAGES=zh_CN.UTF-8   
  LC_PAPER=zh_CN.UTF-8       LC_NAME=C                 
  LC_ADDRESS=C               LC_TELEPHONE=C            
  LC_MEASUREMENT=zh_CN.UTF-8 LC_IDENTIFICATION=C       

Package version:
  evaluate_0.14   glue_1.6.0      graphics_4.1.2  grDevices_4.1.2 highr_0.9      
  knitr_1.37      magrittr_2.0.1  methods_4.1.2   stats_4.1.2     stringi_1.7.6  
  stringr_1.4.0   tools_4.1.2     utils_4.1.2     xfun_0.29       yaml_2.2.1  

reprex::reprex(xfun::session_info("knitr")) 输出结果如下:

xfun::session_info("knitr")
#> R version 4.1.2 (2021-11-01)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 20.04.3 LTS
#> 
#> Locale:
#>   LC_CTYPE=zh_CN.UTF-8       LC_NUMERIC=C              
#>   LC_TIME=zh_CN.UTF-8        LC_COLLATE=zh_CN.UTF-8    
#>   LC_MONETARY=zh_CN.UTF-8    LC_MESSAGES=zh_CN.UTF-8   
#>   LC_PAPER=zh_CN.UTF-8       LC_NAME=C                 
#>   LC_ADDRESS=C               LC_TELEPHONE=C            
#>   LC_MEASUREMENT=zh_CN.UTF-8 LC_IDENTIFICATION=C       
#> 
#> Package version:
#>   evaluate_0.14   glue_1.6.0      graphics_4.1.2  grDevices_4.1.2
#>   highr_0.9       knitr_1.37      magrittr_2.0.1  methods_4.1.2  
#>   stats_4.1.2     stringi_1.7.6   stringr_1.4.0   tools_4.1.2    
#>   utils_4.1.2     xfun_0.29       yaml_2.2.1

Created on 2022-01-15 by the reprex package (v2.0.1)


By filing an issue to this repo, I promise that

I understand that my issue may be closed if I don't fulfill my promises.

chuxinyuan commented 2 years ago

试了下 reprex::reprex(devtools::session_info()) 输出结果也有问题。不同的地方如下:

reprex::reprex(devtools::session_info()) 输出的错误信息:

#>  setting  value
#>  ui       X11

devtools::session_info() 输出的正确信息:

 setting  value
 ui       RStudio
 rstudio  1.4.1717 Juliet Rose (desktop)

所以我觉得这应该是 reprex 包的问题。

yihui commented 2 years ago

这是因为 reprex 在新的 R 进程中运行代码,而不是在当前 R 进程中。新的 R 进程不知道当前 R 进程中关于 RStudio 的任何信息。