VSCode-R-Debugger icon indicating copy to clipboard operation
VSCode-R-Debugger copied to clipboard

.Rprofile never gets to run if "workingDirectory" is not set to ${workspaceFolder}

Open EricBataller opened this issue 11 months ago • 1 comments

Hi there

In the configuration.md documentation, section 3.1 (Launch Requests) says the following:

"workingDirectory": An absolute path to the desired work directory. Defaults to the workspace folder. The R process is always launched in the workspace folder (reading the .Rprofile there) and then changes directory.

From this fragment, I would expect R-debugger to:

  1. Start always on the workspace folder ${workspaceFolder}.
  2. Run the .Rprofile in the workspace folder (if any).
  3. Switch working directory to that specified by the argument "workingDirectory" in the respective R-debugger configuration the user is running from launch.json file.

However, it seems like .Rprofile never gets to run if "workingDirectory" is not set to ${workspaceFolder}.

To Reproduce For a dummy example, let the following be our project structure:

my_root                                # Our workspace directory
  ├── .vscode   
  │       └── launch.json    
  ├── .Rprofile       
  └── subdirectory
           └── bye_world.R 

Let .Rprofile be:

Sys.setenv("MESSAGE" = "hello world!")

Let bye_world.R be:

print(Sys.getenv("MESSAGE"))
print('bye world!')

If we let launch.json be:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "R-Debugger",
            "name": "Debug R-File",
            "request": "launch",
            "debugMode": "file",
            "workingDirectory": "${workspaceFolder}",
            "file": "${file}"
        }

    ]
}

and then we proceed to launch R-debugger from file bye_world.R, the debugger will first run .Rprofile and then proceed with bye_world.R, just to obtain the expected output:

[1] "hello world!"
[1] "bye world!"

However, if we let launch.json be:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "R-Debugger",
            "name": "Debug R-File",
            "request": "launch",
            "debugMode": "file",
            "workingDirectory": "${workspaceFolder}/subdirectory",
            "file": "${file}"
        }

    ]
}

One would still expect R-debugger to run the .Rprofile, but that's not the case, as revealed by the output obtained by running the debugger from file bye_world.R, where we can see that MESSAGE variable never gets defined:

[1] ""
[1] "bye world!"

Is this the expected behaviour (and thus the documentation in configuration.md is a bit misleading), or should the debugger run .Rprofile despite the "workingDirectory" specified?

Desktop:

  • R Version: 4.2.2
  • vscDebugger Version: 0.5.2
  • vscode-r-debugger Version: 0.5.4

EricBataller avatar Mar 13 '24 18:03 EricBataller

Thanks for opening this issue and the detailed info. This is the intended behaviour. The documentation in configuration.md was outdated, sorry about that. https://github.com/ManuelHentschel/VSCode-R-Debugger/commit/eb4ebeb6666d28bd653f3569630f1b1e3ff1ff98 updates the documentation accordingly.

ManuelHentschel avatar Mar 14 '24 07:03 ManuelHentschel