2

Edit

I have narrowed down the problem thanks to @MikaelJagan.

When I run the command readLines("/System/Library/CoreServices/SystemVersion.plist") in the RStudio console, I obtain

 [1] "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"                                                                
 [2] "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
 [3] "<plist version=\"1.0\">"                                                                                   
 [4] "<dict>"                                                                                                    
 [5] "\t<key>ProductBuildVersion</key>"                                                                          
 [6] "\t<string>21C52</string>"                                                                                  
 [7] "\t<key>ProductCopyright</key>"                                                                             
 [8] "\t<string>1983-2021 Apple Inc.</string>"                                                                   
 [9] "\t<key>ProductName</key>"                                                                                  
[10] "\t<string>macOS</string>"                                                                                  
[11] "\t<key>ProductUserVisibleVersion</key>"                                                                    
[12] "\t<string>12.1</string>"                                                                                   
[13] "\t<key>ProductVersion</key>"                                                                               
[14] "\t<string>12.1</string>"                                                                                   
[15] "\t<key>iOSSupportVersion</key>"                                                                            
[16] "\t<string>15.2</string>"                                                                                   
[17] "</dict>"                                                                                                   
[18] "</plist>"

and when I run it in an R session in the terminal, I obtain

 [1] "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
 [2] "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
 [3] "<plist version=\"1.0\">"
 [4] "<dict>"
 [5] "\t<key>ProductBuildVersion</key>"
 [6] "\t<string>21C52</string>"
 [7] "\t<key>ProductCopyright</key>"
 [8] "\t<string>1983-2021 Apple Inc.</string>"
 [9] "\t<key>ProductName</key>"
[10] "\t<string>Mac OS X</string>"
[11] "\t<key>ProductUserVisibleVersion</key>"
[12] "\t<string>10.16</string>"
[13] "\t<key>ProductVersion</key>"
[14] "\t<string>10.16</string>"
[15] "\t<key>iOSSupportVersion</key>"
[16] "\t<string>15.2</string>"
[17] "</dict>"
[18] "</plist>"

I'm not sure why there are different, since I'm providing an absolute path?


Original question

If I open RStudio and type sessionInfo() into the console, it returns:

R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.1

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

locale:
[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] compiler_4.1.1 tools_4.1.1  

However, if I create a R Markdown file, where I include the same command, the knitted HTML file displays

## R version 4.1.1 (2021-08-10)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Big Sur 10.16
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
## 
## locale:
## [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] digest_0.6.29   R6_2.5.1        jsonlite_1.7.2  magrittr_2.0.1 
##  [5] evaluate_0.14   rlang_0.4.12    stringi_1.7.6   jquerylib_0.1.4
##  [9] bslib_0.3.1     rmarkdown_2.11  tools_4.1.1     stringr_1.4.0  
## [13] xfun_0.29       yaml_2.2.1      fastmap_1.1.0   compiler_4.1.1 
## [17] htmltools_0.5.2 knitr_1.37      sass_0.4.0

Notably, the operating system in incorrect in the knitted version. I am running Monterey, not Big Sur. Is there an explanation for this?

max
  • 4,141
  • 5
  • 26
  • 55
  • 2
    You have invented a time machine. New physics! – IRTFM Jan 13 '22 at 02:29
  • 1
    The `knitr` author suggested in an [answer](https://stackoverflow.com/questions/34591487) to a different question that knitting happens in a new R process launched via `Rscript`. So what is the result of `Rscript -e "osVersion"` in Terminal? – Mikael Jagan Jan 13 '22 at 03:42
  • Interesting, yes you are correct, when I run `Rscript -e "osVersion"` at the terminal it returns `[1] "macOS Big Sur 10.16"`, which is the wrong operating system – max Jan 13 '22 at 03:53
  • Is it possible that you have two builds of R installed? What is the result of `Sys.getenv("R_HOME")` in RStudio? And what is the result of `R RHOME` in Terminal? Or maybe `Rscript -e "Sys.getenv(\"R_HOME\")"` in Terminal? – Mikael Jagan Jan 13 '22 at 04:04
  • All three of the commands you listed give the same result: `/Library/Frameworks/R.framework/Resources` – max Jan 13 '22 at 04:10
  • `osVersion` is initialized to `utils:::.osVersion()` at startup. Try debugging into that function in RStudio and in an R process launched from Terminal to see where the paths diverge. – Mikael Jagan Jan 13 '22 at 04:28
  • @MikaelJagan you are totally right. I can reproduce the problem if I just run `sessionInfo()` from R in a terminal window, which returns Big Sur. Compared to in Rstudio which returns Monterey. Not sure how to figure out what's being run different... – max Jan 13 '22 at 04:57
  • Does the value of `utils:::.osVersion()` differ between the two R processes? If so, then run `debug(utils:::.osVersion); utils:::.osVersion()`. This will take you "inside" of the `.osVersion` call (see [here](https://github.com/wch/r-source/blob/61ff4208935c0d29f78d145e22563595498f3ecc/src/library/utils/R/sessionInfo.R#L22-L92)), starting from before the first statement is evaluated. Each time you hit `Return`, R will evaluate a statement. – Mikael Jagan Jan 13 '22 at 05:10
  • In between statements, you can look at the value of variables in the calling environment, like you would at a regular R prompt (type the name and hit `Return`). I'm particularly interested in the value of `ver` after [this statement](https://github.com/wch/r-source/blob/61ff4208935c0d29f78d145e22563595498f3ecc/src/library/utils/R/sessionInfo.R#L52) is evaluated. Since `ver` is obtained [from an absolute path](https://github.com/wch/r-source/blob/61ff4208935c0d29f78d145e22563595498f3ecc/src/library/utils/R/sessionInfo.R#L48), its value should be fixed... – Mikael Jagan Jan 13 '22 at 05:13
  • @MikaelJagan good advice, thank you. I have narrowed down the problem. When I run the command `readLines("/System/Library/CoreServices/SystemVersion.plist")` in RStudio, I get different output than if I run it in an R session at the terminal. How can this be so, since it's an absolute path? See the edit above for details. – max Jan 13 '22 at 05:35
  • That's very cool - now we have to look at what `readLines` and `file` (which is called from `readLines`) are doing, but that's much harder, since they are implemented in C... – Mikael Jagan Jan 13 '22 at 05:49
  • Might be worth asking on the `R-devel` mailing list, since it really _seems_ like a bug. You can subscribe [here](https://stat.ethz.ch/mailman/listinfo/r-devel). If you do ask there, then link to this question. – Mikael Jagan Jan 13 '22 at 05:51
  • Actually, it depends. What are the actual contents of that file? If the `readLines` output is correct in R but wrong in RStudio, then it could be a bug in RStudio. – Mikael Jagan Jan 13 '22 at 06:03
  • As far as I can tell, the output in RStudio is the correct one – max Jan 13 '22 at 15:00
  • 1
    Then `R-devel` is probably the best forum for your question. There, it is more likely to be seen and answered by an R Core Team member. – Mikael Jagan Jan 13 '22 at 15:27

0 Answers0