Listing files in a directory using list.files ()
I am on Mac OS X 10.9.4 Maverics. I am using R console to download some files (using Rstudio does not affect my problem), R version 3.1.1, GUI 1.65 Snow Leopard build (6784). I have loaded some data using the following code:
dataset_url <- "http://s3.amazonaws.com/practice_assignment/diet_data.zip"
download.file(dataset_url, "diet_data.zip")
unzip("diet_data.zip", exdir = "diet_data")
Then if I check my directory:
getwd()
# [1] "/Users/katarinamayer/Desktop/diet_data"
list.files("diet_data")
# character(0)
But if I just type:
list.files()
# [1] "Andy.csv" "David.csv" "John.csv" "Mike.csv" "Steve.csv" "weightmedian.R"
Why can't I get a list of my files when I specify my directory using list.files("diet_data")
?
source to share
You are already in the directory diet_data
as shown in the output getwd()
. By default, list.files()
will display files in the path returned getwd()
.
If you do setwd("/Users/katarinamayer/Desktop/")
, then do list.files("diet_data")
, I trust that you will observe the behavior that you expect.
source to share