quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.69k stars 297 forks source link

Unable to find the install of R on Windows 11 under Parallels #6960

Closed coatless closed 1 month ago

coatless commented 11 months ago

Bug description

Using Parallels on an ARM x64 mac, I'm trying to setup an R environment for Windows. Everything functions well except for quarto. For some reason, quarto's self-check detects the version of R on the path, but for whatever reason fails to acknowledge that R is installed.

Steps to reproduce

Steps here would be to:

  1. Open Parallels 18 or 19
  2. Install the Windows 11 Image
  3. Install R
  4. Install RStudio
  5. Install Quarto
  6. Run commands in command shell ( where, R/Rscript --version, quarto check)

Checking the R Install from within the RStudio Terminal:

C:\Users\ronin\Documents\testing-1-2-3>where R
C:\Program Files (x86)\R\R-4.3.1\bin\x64\R.exe

C:\Users\ronin\Documents\testing-1-2-3>R --version
R version 4.3.1 (2023-06-16 ucrt) -- "Beagle Scouts"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.

Checking the Rscript Install from within the RStudio Terminal:

C:\Users\ronin\Documents\testing-1-2-3>where Rscript
C:\Program Files (x86)\R\R-4.3.1\bin\x64\Rscript.exe

C:\Users\ronin\Documents\testing-1-2-3>Rscript --version
Rscript (R) version 4.3.1 (2023-06-16)

Running quarto check with QUARTO_LOG_LEVEL=DEBUG

C:\Users\ronin\Documents\testing-1-2-3>set QUARTO_LOG_LEVEL=DEBUG

C:\Users\ronin\Documents\testing-1-2-3>quarto check
Quarto version: 1.4.376
Quarto 1.4.376
[>] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.8: OK
      Dart Sass version 1.55.0: OK
      Deno version 1.33.4: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
      Version: 1.4.376
      Path: C:\Program Files\Quarto\bin
      CodePage: 1252

[>] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[>] Checking LaTeX....................OK
      Tex:  (not detected)

Loaded deno-dom-native
(|) Checking basic markdown render....Windows: Using code page 1252
(-) Checking basic markdown render....[trace] Parsed [Plain [Str "long"]] at line
1
[trace] Parsed [Plain [Str "en"]] at line 1
[trace] Parsed [Plain [Str "true"]] at line 1
[trace] Parsed [Plain [Str "1.4.376"]] at line 1
[trace] Parsed [Plain [Str "Title"]] at line 1
[trace] Parsed [Plain [Str "Table",Space,Str "of",Space,Str "contents"]] at line 1[trace] Parsed [] at line 5
[trace] Parsed [Header 2 ("header",[],[]) [Str "Header"]] at line 8
[>] Checking basic markdown render....OK

[>] Checking Python 3 installation....(None)

      Unable to locate an installed version of Python 3.
      Install Python 3 from https://www.python.org/downloads/

-- Searching for R binary --
Looking for 'Rscript' in QUARTO_R: undefined
Looking for 'Rscript' in R_HOME: C:/PROGRA~2/R/R-43~1.1
Looking for 'Rscript' in PATH.
Found in PATH at C:\Program Files (x86)\R\R-4.3.1\bin\x64\Rscript.exe
[>] Checking R installation...........(None)

      Unable to locate an installed version of R.
      Install R from https://cloud.r-project.org/

[NotebookContext]: Starting Cleanup

Notice, that thee "checking R installation" step returns a "Found in PATH"; but subsequently reports it as being missing?

Screenshot of the Windows 11 VM running R & RStudio

Expected behavior

Quarto should respond with true instead of false.

Actual behavior

Quarto found the path and said the R installation wasn't present.

Your environment

Quarto check output

See above.

mcanouil commented 11 months ago

In some aspects in might be related to:

The message is a default message which under some circumstances is not really accurate of the status.

cderv commented 11 months ago

Yes exactly, it seems to be the case here of not enough precise error message. We added the DEBUG step recently to help - it seems we may need to add more debug step.

Found in PATH at C:\Program Files (x86)\R\R-4.3.1\bin\x64\Rscript.exe

What happens after this is that a simple document will be rendered to check R configuration, especially for knitr and rmarkdown being installed. The file run is share\capabilities\knitr.R which is in the Quarto installation folder.

So we do run this file with Rscript found https://github.com/quarto-dev/quarto-cli/blob/main/src/resources/capabilities/knitr.R

Then we parse the results to check the information received. If running this script fails for some reason, then it seems we don't throw a specific issue but the generic one being R not correctly found and running. We could definitely improve those messages.

Out of curiosity, can you run this R script on your side to understand what fails in it ?

coatless commented 11 months ago

So, I grabbed the knitr.R script and placed it into the same Quarto directory. The script finished correctly with the following output:

--- YAML_START ---
versionMajor: 4
versionMinor: 3
versionPatch: 1
home: C:/PROGRA~2/R/R-43~1.1
libPaths:
  - "C:/Users/ronin/AppData/Local/R/win-library/4.3"
  - "C:/Program Files (x86)/R/R-4.3.1/library"
packages:
  knitr: "1.44"
  rmarkdown: "2.25"
--- YAML_END ---

I've taken a screenshot of the R package library (rmarkdown and knitr) are shown in the User-library.

Screenshot of the results from running `knitr.R` under `Rscript.exe`

So, I think this must be failing elsewhere. Can I poke at this somewhere else?

VM resources VM RAM & CPUs VM Storage
cderv commented 10 months ago

@coatless I merged #7013 which means we'll be able to have better error message to understand where the error happens, especially with verbose mode activated.

This will be available in next pre-release build, or already in main.

coatless commented 10 months ago

@cderv thanks for the update. At the moment, I don't think the updated checks are in 1.4.392. So, I'll circle back later this weekend when a new build is available.

mcanouil commented 10 months ago

Indeed, the fix should be in the next build (1.4.392 was compiled two hours before).

cderv commented 10 months ago

FYI first version to have the update is v1.4.394

coatless commented 10 months ago

Thanks! I downloaded and installed version 1.4.398. Re-running quarto check. I'm seeing:

R succesfully found at C:\Program Files (x86)\R\R-4.3.1\bin\x64\Rscript.exe.
However, a problem was encountered when checking configurations of packages.
Please check your installation of R.
quarto bad R package configuration

It looks like there are two knitr components with only a slight difference (KnitrCapabilities and knitrCapabilities) present? one upper case and one lower case?

https://github.com/quarto-dev/quarto-cli/blob/a24bfabea842c4485abd86b608d8293e4a436a67/src/command/check/check.ts#L23-L24

cderv commented 10 months ago

However, a problem was encountered when checking configurations of packages.

Ok so this means that the issue happens at the step of running the configuration check. This returns undefined: https://github.com/quarto-dev/quarto-cli/blob/a24bfabea842c4485abd86b608d8293e4a436a67/src/command/check/check.ts#L296

Meaning something in there is not working as expected https://github.com/quarto-dev/quarto-cli/blob/a24bfabea842c4485abd86b608d8293e4a436a67/src/core/knitr.ts#L59-L99

especially with verbose mode activated.

As I suggested before, can you really run in verbose mode please so that we have more debug message to look at and know what is really happening in the check ?

It looks like there are two knitr components with only a slight difference (KnitrCapabilities and knitrCapabilities) present? one upper case and one lower case?

Yes this is a typescript think

KnitrCapabilities is an interface object which defines what caps content is expected to be https://github.com/quarto-dev/quarto-cli/blob/a24bfabea842c4485abd86b608d8293e4a436a67/src/core/knitr.ts#L15-L22 https://github.com/quarto-dev/quarto-cli/blob/a24bfabea842c4485abd86b608d8293e4a436a67/src/command/check/check.ts#L289

knitrCapabilities is a function to run for checking configuration that returns the object saved to caps https://github.com/quarto-dev/quarto-cli/blob/a24bfabea842c4485abd86b608d8293e4a436a67/src/core/knitr.ts#L59 https://github.com/quarto-dev/quarto-cli/blob/a24bfabea842c4485abd86b608d8293e4a436a67/src/command/check/check.ts#L296

coatless commented 10 months ago

@cderv whoops, sorry for not setting QUARTO_LOG_LEVEL=DEBUG on that last one. When I set it, I end up getting:

-- Searching for R binary --
Looking for 'Rscript' in QUARTO_R: undefined
Looking for 'Rscript' in R_HOME: C:/PROGRA~2/R/R-43~1.1
Looking for 'Rscript' in PATH.
Found in PATH at C:\Program Files (x86)\R\R-4.3.1\bin\x64\Rscript.exe

++R found at C:\Program Files (x86)\R\R-4.3.1\bin\x64\Rscript.exe is working.
-- Checking knitr engine capabilities --
(|) Checking R installation...........
++ Problem with results of knitr capabilities check.
[>] Checking R installation...........(None)

R succesfully found at C:\Program Files (x86)\R\R-4.3.1\bin\x64\Rscript.exe.
However, a problem was encountered when checking configurations of packages.
Please check your installation of R.
Run with `QUARTO_LOG_LEVEL=DEBUG` set
cderv commented 10 months ago

Thank you. This is really puzzling...

-- Checking knitr engine capabilities --

We do go to the checking stage https://github.com/quarto-dev/quarto-cli/blob/a24bfabea842c4485abd86b608d8293e4a436a67/src/core/knitr.ts#L62-L66

++ Problem with results of knitr capabilities check.

But something is not working as it should as we go the the else part in there https://github.com/quarto-dev/quarto-cli/blob/a24bfabea842c4485abd86b608d8293e4a436a67/src/core/knitr.ts#L87-L90

From this if https://github.com/quarto-dev/quarto-cli/blob/a24bfabea842c4485abd86b608d8293e4a436a67/src/core/knitr.ts#L67

So the command that should have run which is what we talked about before (https://github.com/quarto-dev/quarto-cli/issues/6960#issuecomment-1733916136) is

The call should be equivalent to this line run from testing-1-2-3 folder

C:\Program Files (x86)\R\R-4.3.1\bin\x64\Rscript.exe <quarto-dir>/share/capabilities/knitr.R

You could try running this directly with the correct absolute path to the script (not just copying knitr.R file).

Maybe there is something in the path (space ? unexpected character ?), or something in a .Rprofile that does error. (maybe we should use --vanilla for this call 🤔

Also Let me see if I can improve the debug log to add the R error if any.

You could try to debug in typescript directly using VSCODE debug feature with deno. If I had access I would have tried that.

coatless commented 10 months ago

@cderv Thanks. I think this might be the path with spaces on Windows. Without quotations around on the path, e.g.

C:/Program Files (x86)/R/R-4.3.1/bin/x64/Rscript.exe C:/Users/ronin/AppData/Local/Programs/Quarto/share/capabilities/kn/share/capabilities/knitr.R

I'm getting:

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

If I run it using quotations around the Rscript.exe, e.g.

"C:/Program Files (x86)/R/R-4.3.1/bin/x64/Rscript.exe" C:/Users/ronin/AppData/Local/Programs/Quarto/share/capabilities/kn/share/capabilities/knitr.R

I get:

--- YAML_START ---
versionMajor: 4
versionMinor: 3
versionPatch: 1
home: C:/PROGRA~2/R/R-43~1.1
libPaths:
  - "C:/Users/ronin/AppData/Local/R/win-library/4.3"
  - "C:/Program Files (x86)/R/R-4.3.1/library"
packages:
  knitr: "1.44"
  rmarkdown: "2.25"
--- YAML_END ---

Note: The result is the same if I run --vanilla.

Screenshot of the programs path with space being problematic

Do you have any notes on the VS Code portion? Is there a devcontainer I can toy with?

mcanouil commented 10 months ago

@coatless there is no devcontainer config, but there is the VSCode configuration/recommended extensions in the Quarto CLI repository. I might have a devcontainer.json which allow to compile the repository thus has everything needed. Let me check.

EDIT: here an example I used in the past https://github.com/mcanouil/quarto-cli-issue6440

cderv commented 10 months ago

I think this might be the path with spaces on Windows. Without quotations around on the path

I do have a space on Windows too and this is running fine

Quarto version: 1.4.398
Quarto 1.4.398
-- Searching for R binary --
Looking for 'Rscript' in QUARTO_R: C:\Program Files\R\R-4.3.1\bin\Rscript.exe
Found in C:\Program Files\R\R-4.3.1\bin

++R found at C:\Program Files\R\R-4.3.1\bin\Rscript is working.
-- Checking knitr engine capabilities --
(|) Checking R installation...........++ Activating rlang global_entrace

(|) Checking R installation...........
++ Parsing results to get informations about knitr capabilities
[>] Checking R installation...........OK
      Version: 4.3.1
      Path: C:/PROGRA~1/R/R-43~1.1
      LibPaths:
        - C:/Users/chris/AppData/Local/R/win-library/4.3
        - C:/Program Files/R/R-4.3.1/library
      knitr: 1.44
      rmarkdown: 2.25

Loaded deno-dom-native
-- Searching for R binary --
Looking for 'Rscript' in QUARTO_R: C:\Program Files\R\R-4.3.1\bin\Rscript.exe
Found in C:\Program Files\R\R-4.3.1\bin
(-) Checking Knitr engine render......Windows: Using code page 1252
(/) Checking Knitr engine render......[trace] Parsed [Plain [Str "long"]] at line 1
[trace] Parsed [Plain [Str "en"]] at line 1
[trace] Parsed [Plain [Str "true"]] at line 1
[trace] Parsed [Plain [Str "1.4.398"]] at line 1
[trace] Parsed [Plain [Str "Title"]] at line 1
[trace] Parsed [Plain [Str "Table",Space,Str "of",Space,Str "contents"]] at line 1
[trace] Parsed [] at line 5
[trace] Parsed [Header 2 ("header",[],[]) [Str "Header"]] at line 8
[trace] Parsed [] at line 10
[trace] Parsed [CodeBlock ("",["r","cell-code"],[]) "1 + 1"] at line 14
[trace] Parsed [] at line 16
[trace] Parsed [CodeBlock ("",[],[]) "[1] 2"] at line 21
[trace] Parsed [Div ("",["cell-output","cell-output-stdout"],[]) [CodeBlock at line 22
[trace] Parsed [Div ("",["cell"],[]) [CodeBlock ("",["r","cell-code"],[]) " at line 25
[>] Checking Knitr engine render......OK

[NotebookContext]: Starting Cleanup

So I do think we are correctly calling and quoting it when called through Deno. As it seems you can run the script on its own, it could be something from Deno call directly.

Though I have R in Programs files and not the (x86) folder; Could it be that ? Would be odd... This is where default installer install it (either using rig or the usual CRAN installer)

I am really puzzled and we are probably missing something;

Do you have any notes on the VS Code portion?

Not specific to Quarto and Deno debugging. We have a launch.json on the repo, and some setup but it would definitely require some documentation for Windows usage;

Is there a devcontainer I can toy with?

Not yet. We should probably try to make one... I think there were some around but not one dedicated to debugging quarto-cli Good idea!

cderv commented 10 months ago

I added one more commit to get the more information about the returned values from the capabilities check. You need either to wait for next build or use the dev version from git clone

coatless commented 10 months ago

@cderv pre-release build has yet to update. I'll probably compile from source later tonight and explore the VS profile.

cscheid commented 10 months ago

(building now https://github.com/quarto-dev/quarto-cli/actions/runs/6442153887 Once the workflow finishes, there'll be a new release on the page)

coatless commented 10 months ago

@cderv under 1.4.404 the "Checking R Installation ... " takes a bit more time, but I get the following output:

screenshot with updated build of quarto check results
-- Searching for R binary --
Looking for 'Rscript' in QUARTO_R: undefined
Looking for 'Rscript' in R_HOME: C:/PROGRA~2/R/R-43~1.1
Looking for 'Rscript' in PATH.
Found in PATH at C:\Program Files (x86)\R\R-4.3.1\bin\x64\Rscript.exe

++R found at C:\Program Files (x86)\R\R-4.3.1\bin\x64\Rscript.exe is working.
-- Checking knitr engine capabilities --
(|) Checking R installation...........
++ Problem with results of knitr capabilities check.
    Return Code: false
    with stdout from R:
--- YAML_START ---
versionMajor: 4
versionMinor: 3
versionPatch: 1
home: C:/PROGRA~2/R/R-43~1.1
libPaths:
  - "C:/Users/ronin/AppData/Local/R/win-library/4.3"
  - "C:/Program Files (x86)/R/R-4.3.1/library"
packages:
  knitr: "1.44"
  rmarkdown: "2.25"
--- YAML_END ---

[>] Checking R installation...........(None)

R succesfully found at C:\Program Files (x86)\R\R-4.3.1\bin\x64\Rscript.exe.
However, a problem was encountered when checking configurations of packages.
Please check your installation of R.

[NotebookContext]: Starting Cleanup
cderv commented 10 months ago
(|) Checking R installation...........
++ Problem with results of knitr capabilities check.
    Return Code: false
    with stdout from R:
--- YAML_START ---
versionMajor: 4
versionMinor: 3
versionPatch: 1
home: C:/PROGRA~2/R/R-43~1.1
libPaths:
  - "C:/Users/ronin/AppData/Local/R/win-library/4.3"
  - "C:/Program Files (x86)/R/R-4.3.1/library"
packages:
  knitr: "1.44"
  rmarkdown: "2.25"
--- YAML_END ---

So you get the above...

This means that the script executed correctly, it has a stdout as expected and no stderr. However Return Code: false means that success is not true 🤯

https://github.com/quarto-dev/quarto-cli/blob/5ad97e0c8c131dbdc91706b0716351daa30c40d6/src/core/knitr.ts#L63-L67

I am really puzzled by the fact that everything seems fine, but the command has a success code which is not true... It should be the result of process.status https://github.com/quarto-dev/quarto-cli/blob/5ad97e0c8c131dbdc91706b0716351daa30c40d6/src/core/process.ts#L155-L156 https://github.com/quarto-dev/quarto-cli/blob/5ad97e0c8c131dbdc91706b0716351daa30c40d6/src/core/process.ts#L164

I forgot to add the process.code information to get the error code. So it is added now and available in next build.

@dragonstyle @cscheid any idea on what could cause our call to Deno.Run for running Rscript to correctly execute, have a stdout content, no stderr but still a status() which is false ?

@coatless if this an issue only with quarto check knitr or do you have also same problem with rendering a document with knitr engine ?

I am quite puzzled by this behavior ...

coatless commented 10 months ago

@cderv So, triggering a knit directly on the document works fine:

knitr::knit("testing-1-2-3.qmd")
#   processing file: testing-1-2-3.qmd 
#   1/2                   
#   2/2 [unnamed-chunk-1] 
#   output file: testing-1-2-3.md 
# [1] "testing-1-2-3.md"
Directly running knitr::knit() on the document

The only issue I can think of is an installation issue with admin rights. Though, I don't think that makes sense.

On Windows 10 VMs, I never had an issue like this.

coatless commented 10 months ago

Also, I spun up a dev build inside of the VM following the README.

./configure.cmd
Screenshot of quarto development running in VS Code on Win 11 VM

Though, set QUARTO_LOG_LEVEL=DEBUG didn't yield the extended output.

Quarto debug log level not showing extended output

Any suggestions or things I should read through?

cderv commented 10 months ago

is this an issue only with quarto check knitr or do you have also same problem with rendering a document with knitr engine ?

By this I mean, do you have an issue when doing quarto render testing-1-2-3.qmd ? Is it only an issue with quarto check and R ?

Any suggestions or things I should read through?

I think you are working on powershell so setting environment variable is done by this command

$env:QUARTO_LEVEL_DEBUG="DEBUG"

I don't think set (or Set-Variable) works for environment variables. (which quarto will check)

By setting this environment with dev version, we could now try to debug interactively withing vscode to understand what happens. I can try to guide you here (or maybe it would be more efficient to program a live session together to try ?)

d-pendlebury commented 7 months ago

Was this ever solved? I am having the exact same issue rendering quarto using parallels on a mac.

cderv commented 7 months ago

@d-pendlebury no it was not. Otherwise, this would have been closed, and the milestone would not have been set to 1.5. Those are usually hints that this is still an ongoing issue.

For this one, we are missing information on what could be the problem. The issue was not reproducible on our part.

I am having the exact same issue rendering quarto using parallels on a Mac.

It is probably not exactly the same as this issue is about Windows 11 and yours is about Mac. The error Unable to locate an installed version of R. can happen in many situations when Quarto does not manage to run the R checks for some reason.

To keep threads as scoped and clean as possible, could you open a new issue with as much detail as possible to help us help you?

Please try with Quarto 1.4 (https://quarto.org/docs/download/). Also, I would advise to activate verbose mode (https://quarto.org/docs/troubleshooting/#verbose-mode) and stack trace (https://quarto.org/docs/troubleshooting/#get-a-stack-trace)

Thank you very much!

coatless commented 7 months ago

@cderv I promise to revisit in this upcoming week. Sorry for dropping off on this one; Windows is... well, Windows.

cderv commented 7 months ago

No worries ! Take you times. Not easy one to investigate and understand unfortunately. If I can help in any way, please reach out to me.

Also Quarto 1.4 RC is out, and stable release is very soon. So do not forget to update, and we will do our best to fix any issue for 1.5 !

d-pendlebury commented 7 months ago

@cderv I could have been more specific in my post, but from what I can tell it does seem to be extremely similar to this one. I am using R on Windows 11 under Parallels Desktop 19 for Mac. Running commands (where R, RScript -- version, and quarto check) gives me the following outputs and errors:

image image image
cderv commented 7 months ago

Thanks a lot for the additional information, and the debug output. I indeed misunderstood this was Windows on Mac too in your case.

It seems to be a common factor.

The issue is coming from https://github.com/quarto-dev/quarto-cli/blob/945b7d1bc6729d48af1e7b39894b3df5879288f2/src/core/knitr.ts#L101-L111

which happens when calling Rscript capabilities/knitr.R resulted in an error somehow. https://github.com/quarto-dev/quarto-cli/blob/945b7d1bc6729d48af1e7b39894b3df5879288f2/src/core/knitr.ts#L67-L71

Meaning

This is indeed the same conclusion as https://github.com/quarto-dev/quarto-cli/issues/6960#issuecomment-1752565609

Though now, we have the error code. The error code we get now with the debug output could give some hints maybe... It seems to be -1073741819.

It may seem unrelated, but when I abruptly search on google, it gives me results for Windows 10 issue. 🤷

I really don't know what is causing this, especially because it seems running the R script for capabilities returned ok in thread above (https://github.com/quarto-dev/quarto-cli/issues/6960#issuecomment-1734934532)

This would mean this is something about Deno executing Rscript on Windows virtually running on Mac...

This will not be easy to debug ! 😓

cscheid commented 5 months ago

(I think I had a conversation with @kevinushey about weird status errors from R in Apple Silicon windows settings. Kevin, does this ring a bell for you?)

kevinushey commented 5 months ago

I recall seeing this same issue before, but I'm no longer able to reproduce it on my Windows VM. In my case, there's a chance it was related to some changes in a particular version of the Windows Insider builds, as that was wreaking havoc on all Cygwin binaries on my machine. The most recent Windows update appears to have resolved that.

I also have a vague recollection of similar issues on Windows where an R crash on exit would occur with older versions of some R packages (maybe processx or something in that ecosystem?) so it may also be worth checking if updating / reinstalling rmarkdown and its dependencies makes a difference?

EDIT: Found the issue I was thinking of, at https://github.com/r-lib/cli/issues/494.

github-actions[bot] commented 1 month ago

Thank you for using Quarto and reporting an issue!

Unfortunately, this issue is now considered stale because it has been opened since 14 days without providing a "working" reproducible example to help us investigate. If you are still facing the issue, please review the "Bug Reports" guide on how to provide a fully reproducible example as a self-contained Quarto document or a link to a Git repository. Without a reproducible example, it is unlikely that the issue will be addressed.

You can share a Quarto document using the following syntax, i.e., using more backticks than you have in your document (usually four ````).

````qmd
---
title: "Reproducible Quarto Document"
format: html
---

This is a reproducible Quarto document using `format: html`.
It is written in Markdown and contains embedded R code.
When you run the code, it will produce a plot.

```{r}
plot(cars)

The end.