Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listing files in a directory using list.files() [duplicate]

Tags:

r

I am on mac OS X 10.9.4 Maverics. I am using R console to download some files (using Rstudio has no effect on my problem), version R 3.1.1, GUI 1.65 Snow Leopard build (6784). I have downloaded 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 I cannot get the list of my files when I specify my directory, using list.files("diet_data")?

like image 796
carpediem Avatar asked Jan 09 '23 19:01

carpediem


1 Answers

You are already inside the diet_data directory, as indicated by the output of getwd(). By default, list.files() will list the files on the path returned by getwd().

If you setwd("/Users/katarinamayer/Desktop/"), then execute list.files("diet_data"), I believe you will observe the behaviour that you expect.

like image 88
x4nd3r Avatar answered Jan 19 '23 07:01

x4nd3r