[R-pkg-devel] dir() function use in R packages
Mark Leeds
m@rk|eed@2 @end|ng |rom gm@||@com
Thu Mar 5 04:12:25 CET 2020
I think you want file.path(). you can use that to make a directory that
includes a path to it.
See ?file.path for more details. Then, you can do something like
mydir ,- file.path(whatever)1, whatever2).
setwd(mydir)
but mydir needs to exist before you do that so check existence first using
file.exists().
On Wed, Mar 4, 2020 at 8:22 PM Jarrett Phillips <phillipsjarrett1 using gmail.com>
wrote:
> 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]]
>
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>
[[alternative HTML version deleted]]
More information about the R-package-devel
mailing list