emacs-ess / ESS

Emacs Speaks Statistics: ESS
https://ess.r-project.org/
GNU General Public License v3.0
623 stars 162 forks source link

Incorrect path expansion on Windows #1253

Open ArcadeAntics opened 1 year ago

ArcadeAntics commented 1 year ago

Hi!

I've created a file ~/test.R which Emacs expands to C:/Users/iris/AppData/Roaming/test.R. When I load that file, R runs .ess.source("~/test.R") which R expands to C:/Users/iris/Documents/test.R and then throws an error about the file not existing. Perhaps .ess.source() could expand the path before passing to source(), something like:

if (.Platform$OS.type == "windows") {
    ## ideally we'd use startsWith(),
    ## but that was introduced in R 3.3.0,
    ## so we'll have to use grepl() instead
    # if (startsWith(file, "~/") || startsWith(file, "~\\")) {

    ## this matches the behaviour of R_ExpandFileName for Windows
    if (grepl("(?i)^~(?![a-z])", file, perl = TRUE, useBytes = TRUE)) {
        file <- paste0(Sys.getenv("APPDATA"), substring(file, 2L))
    }
}

Thank you!