Skip to content

Sourcing an open script file as a job fails if the path contains non-ASCII characters on Windows #6701

Closed

Description

@jarauh

System details

RStudio Edition : Desktop
RStudio Version :  1.2.5033
OS Version      :  Windows 10
R Version       : 3.6.3

Steps to reproduce the problem

  1. Save a ".R"-file in a directory that contains non-ASCII characters (e.g. "Test für RStudio/Vorbereitung.R".
  2. Select "Source -> Source as Local Job"

Describe the problem in detail

The job aborts with an error message (here in German):

In file(filename, "r") :
Kann Datei 'Test f?r RStudio/Vorbereitung.R' nicht �ffnen: Invalid argument

Describe the behavior you expected

The Job starts, runs through and finishes in the same way as it does if it is sourced directly in the R console.

Activity

  1. added and removed on Apr 21, 2020
  2. R-Hannibal commented on Apr 22, 2020

    @R-Hannibal

    @jarauh Thank you so much for reporting this issue, we'll have the dev team take a look.

    I was able to reproduce the issue in RStudio Versions 1.2, 1.3, and 1.4, including the error message that is served up in the Jobs pane below:

    Error in file(filename, "r") : cannot open the connection
    Calls: sourceWithProgress -> parse -> file
    In addition: Warning message:
    In file(filename, "r") :
      cannot open file 'C:/Users/Mario/Documents/0_?/RFileSourceAsJobSCDirectory.R': Invalid argument
    Execution halted
    
  3. added this to the v1.4 milestone on Apr 22, 2020
  4. removed their assignment
    on May 27, 2020
  5. mikebessuille commented on Jun 29, 2020

    @mikebessuille
    Contributor

    ooops didn't mean to close this...

  6. kevinushey commented on Jul 1, 2020

    @kevinushey
    Collaborator

    This is where we form the command used to run R:

    // determine encoding
    std::string encoding = "UTF-8";
    if (!spec_.encoding().empty())
    encoding = spec_.encoding();
    // form the command to send to R
    std::string cmd = "source('" +
    string_utils::utf8ToSystem(
    string_utils::singleQuotedStrEscape(
    session::options().modulesRSourcePath()
    .completePath("SourceWithProgress.R").getAbsolutePath())) +
    "'); sourceWithProgress(script = '" +
    string_utils::utf8ToSystem(
    string_utils::singleQuotedStrEscape(path)) + "', "
    "encoding = '" + encoding + "', "
    "con = stdout(), "
    "importRdata = " + importRdata + ", "
    "exportRdata = " + exportRdata + ");";
    core::system::Options environment;
    // build options for async R process; default to no rdata unless we have other options (most
    // common is a vanilla R process)
    async_r::AsyncRProcessOptions options =
    spec_.procOptions() ? *spec_.procOptions() : async_r::R_PROCESS_NO_RDATA;
    async_r::AsyncRProcess::start(cmd.c_str(), environment, spec_.workingDir(),
    options);

    The issue is likely that the attempt to re-encoded paths from UTF-8 to the system encoding is failing here. We might instead try avoiding this need to re-encode paths by writing out an R script (as UTF-8) and telling R to just source that script as though it were UTF-8 encoded.

  7. 15 remaining items

  8. modified the milestones: v1.4, v1.5 on Oct 19, 2020
  9. mikebessuille commented on Oct 19, 2020

    @mikebessuille
    Contributor

    unfortunately it's too late for this in 1.4 at this point; moving to 1.5

  10. melissa-barca commented on Oct 19, 2020

    @melissa-barca
    Contributor

    Notes for the future:
    @kevinushey It's interesting that this didn't work for you because I retested last week and it worked fine with @jarauh's example. It's may be varying per encoding.

  11. kevinushey commented on Oct 19, 2020

    @kevinushey
    Collaborator

    In my case, I was using Chinese characters + an English locale, and since those cannot be expressed in an English locale (codepage) that's likely why.

  12. modified the milestones: Backlog-3, Later on Oct 5, 2023
  13. gtritchie commented on Jul 20, 2026

    @gtritchie
    Member

    This scenario works in latest RStudio (I tested 2026.08.0-daily+90). I created a folder named 脚本, put a script in it, and was able to source it as a local job. Given the age of this issue, a LOT of code has changed (including a port to Electron and support for utf8 in Windows), so not too surprised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions