On Aug 12, 2010, at 11:51 AM, Stephen Liu wrote:
Hi Barry,
Following 2 commands are useful to me;
row
.names(subset(file.info(list.files(getwd(),full.name=TRUE)),isdir))
showing directories.
row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),!
isdir))
showing files
What is "!" for? TIA
?"!"
(learn to use R help facilities!)
B.R.
Stephen L
----- Original Message ----
From: Barry Rowlingson <b.rowling...@lancaster.ac.uk>
To: Stephen Liu <sati...@yahoo.com>
Cc: r-help@r-project.org
Sent: Thu, August 12, 2010 8:05:10 PM
Subject: Re: [R] Where the data file is stored?
On Thu, Aug 12, 2010 at 12:37 PM, Stephen Liu <sati...@yahoo.com>
wrote:
----- Original Message ----
From: Alain Guillet <alain.guil...@uclouvain.be>
To: Stephen Liu <sati...@yahoo.com>
Cc: r-help@r-project.org
Sent: Thu, August 12, 2010 5:28:32 PM
Subject: Re: [R] Where the data file is stored?
You can find your current working directory with the getwd()
function.
Hi Alain,
Thanks for your advice.
getwd()
[1] "/home/userA"
list.files(getwd())
[1] "Desktop" "Documents" "Downloads"
[4] "examples.desktop" "last-packages.txt" "Music"
[7] "myR" "petdrug.csv" "Pictures"
[10] "Public" "R" "Templates"
[13] "Videos"
list.files(getwd(),full.name=TRUE)
[1] "/home/userA/Desktop"
[2] "/home/userA/Documents"
[3] "/home/userA/Downloads"
[4] "/home/userA/examples.desktop"
[5] "/home/userA/last-packages.txt"
[6] "/home/userA/Music"
[7] "/home/userA/myR"
[8] "/home/userA/petdrug.csv"
[9] "/home/userA/Pictures"
[10] "/home/userA/Public"
[11] "/home/userA/R"
[12] "/home/userA/Templates"
[13] "/home/userA/Videos"
How to show on the printout which is directory? TIA
Use file.info and check the $isdir part of the returned data frame.
For example, to get names of only directories in your working dir, do:
row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),isdir))
a quick modification gets you not-directories (which will be plain
files plus special files):
row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),!
isdir))
see ?file.info and ?files
Barry
______________________________________________
R-help@r-project.org mailing list
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.
David Winsemius, MD
West Hartford, CT
______________________________________________
R-help@r-project.org mailing list
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.