[R] Bug in list.files(full.names=T)

Andrew Simmons @kw@|mmo @end|ng |rom gm@||@com
Mon Dec 20 20:24:29 CET 2021


I've tried a bunch of different R versions, I can't seem to replicate what
you described. Here's the code I used:


R.pattern <- paste0("^R-", .standard_regexps()$valid_R_system_version, "$")
x <- list.files(dirname(R.home()), pattern = R.pattern, full.names = TRUE)
x <- x[file.info(x, extra_cols = FALSE)$isdir]
x <- file.path(x, "bin", "x64", "Rscript")
commands <- shQuote(x)
args <- c("--default-packages=NULL", "--vanilla",
    "-e", shQuote(r"{
        x <- list.files(c(
            "./"         ,
            "C:/"        ,
            "C:/Windows/"
        ), full.names = TRUE)
        x <- x[grepl("//", x, fixed = TRUE)]
        if (length(x))
            print(x)
    }"))
for (command in commands) {
    command <- paste(c(command, args), collapse = " ")
    cat(command, "\n", sep = "")
    system(command)
    cat("\n")
}


which should (theoretically) open every version of R you have installed and
try the code you ran. When I ran it, I found no files with two slashes in a
row:


"C:/PROGRA~1/R/R-2.15.3/bin/x64/Rscript" --default-packages=NULL --vanilla
-e "
        x <- list.files(c(
            \"./\"         ,
            \"C:/\"        ,
            \"C:/Windows/\"
        ), full.names = TRUE)
        x <- x[grepl(\"//\", x, fixed = TRUE)]
        if (length(x))
            print(x)
    "

"C:/PROGRA~1/R/R-3.5.3/bin/x64/Rscript" --default-packages=NULL --vanilla
-e "
        x <- list.files(c(
            \"./\"         ,
            \"C:/\"        ,
            \"C:/Windows/\"
        ), full.names = TRUE)
        x <- x[grepl(\"//\", x, fixed = TRUE)]
        if (length(x))
            print(x)
    "

"C:/PROGRA~1/R/R-3.6.3/bin/x64/Rscript" --default-packages=NULL --vanilla
-e "
        x <- list.files(c(
            \"./\"         ,
            \"C:/\"        ,
            \"C:/Windows/\"
        ), full.names = TRUE)
        x <- x[grepl(\"//\", x, fixed = TRUE)]
        if (length(x))
            print(x)
    "

"C:/PROGRA~1/R/R-4.0.2/bin/x64/Rscript" --default-packages=NULL --vanilla
-e "
        x <- list.files(c(
            \"./\"         ,
            \"C:/\"        ,
            \"C:/Windows/\"
        ), full.names = TRUE)
        x <- x[grepl(\"//\", x, fixed = TRUE)]
        if (length(x))
            print(x)
    "

"C:/PROGRA~1/R/R-4.1.0/bin/x64/Rscript" --default-packages=NULL --vanilla
-e "
        x <- list.files(c(
            \"./\"         ,
            \"C:/\"        ,
            \"C:/Windows/\"
        ), full.names = TRUE)
        x <- x[grepl(\"//\", x, fixed = TRUE)]
        if (length(x))
            print(x)
    "

"C:/PROGRA~1/R/R-4.1.1/bin/x64/Rscript" --default-packages=NULL --vanilla
-e "
        x <- list.files(c(
            \"./\"         ,
            \"C:/\"        ,
            \"C:/Windows/\"
        ), full.names = TRUE)
        x <- x[grepl(\"//\", x, fixed = TRUE)]
        if (length(x))
            print(x)
    "

"C:/PROGRA~1/R/R-4.1.2/bin/x64/Rscript" --default-packages=NULL --vanilla
-e "
        x <- list.files(c(
            \"./\"         ,
            \"C:/\"        ,
            \"C:/Windows/\"
        ), full.names = TRUE)
        x <- x[grepl(\"//\", x, fixed = TRUE)]
        if (length(x))
            print(x)
    "


I can't offer much more, sorry about that. Maybe your session information
could be helpful? utils::sessionInfo()

On Sun, Dec 19, 2021 at 6:40 AM Mario Reutter <mario_reutter using web.de> wrote:

> Dear everybody,
>
> I'm a researcher in the field of psychology and a passionate R user. After
> having updated to the newest version, I experienced a problem with
> list.files() if the parameter full.names is set to TRUE.
> A path separator "/" is now always appended to path in the output even if
> path %>% endsWith("/"). This breaks backwards compatibility in case path
> ends with a path separator. The problem occurred somewhere between R
> version 3.6.1 (2019-07-05) and 4.1.2 (2021-11-01).
>
> Example:
> >> list.files("C:/Data/", full.names=T)
> C:/Data//file.csv
>
> Expected behavior:
> Either a path separator should never be appended in accordance with
> the documentation: "full.names
> a logical value. If TRUE, the directory path is prepended to the file names
> to give a relative file path."
> Or it could only be appended if path doesn't already end with a path
> separator.
>
> My question would now be if this warrants a bug report? And if you agree,
> could someone issue the report since I'm not a member on Bugzilla?
>
> Thank you and best regards,
> Mario Reutter
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list