[R-pkg-devel] dir() function use in R packages

Jarrett Phillips ph||||p@j@rrett1 @end|ng |rom gm@||@com
Thu Mar 5 02:22:25 CET 2020


Hi All,

I am updating my R package that is currently on CRAN.

I am looking to have my main package function iterate through some files in
a directory, but am having some issues.  In my function, I do the following
(I might switch to 'replicate()' instead since non-preallocated for loops
can be very slow):

    file.names <- dir(path, pattern = ".fas")
        for (i in 1:length(file.names)) {
           # read in DNA sequences using 'pegas' package
          seqs <- read.dna(file = file.names[i], format = "fasta")
        }

However, I am uncertain how my function should handle the 'path' argument
to dir(). I could provide 'path' as an explicit argument to my function,
but is there a less direct way?

What I'm after is something like 'file.choose()', except for a folder,
rather than a file.

Has anyone implemented something similar in their R packages?

Thanks!

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list