Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: get list of files but not of directories

Tags:

file

list

r

In R how can I get a list of files in a folder, but not of the directories?

I have tried using dir(), list.files(), list.dirs() with different options, but none of them seems to work.

like image 445
lucacerone Avatar asked Feb 27 '14 12:02

lucacerone


People also ask

How do I get a list of files in a folder in R?

To list all files in a directory in R programming language we use list. files(). This function produces a list containing the names of files in the named directory. It returns a character vector containing the names of the files in the specified directories.

What is dir () in R?

Basic R Syntax: The dir R function returns a character vector of file and/or folder names within a directory.

How do I open a folder in R?

You can think of R as having a file explorer window open invisibly in the background. You can see the folder that's open at the moment by typing getwd() at the console. setwd() tells R to open a different folder instead. setwd('../') tells R to go up to a parent directory.


1 Answers

setdiff(list.files(), list.dirs(recursive = FALSE, full.names = FALSE)) 

will do the trick.

like image 62
Sven Hohenstein Avatar answered Sep 21 '22 22:09

Sven Hohenstein