First I changed the working directory to .Rprofile. Then I tried to select a file using file.choose().
When you first start file.choose, a list of directories is displayed by default. Subsequent executions show the current directory.
> getwd()
[1] "C:/Users/dinesh/Desktop/lab/M1/sp500"
> mydata=read.csv(file.choose(),stringsAsFactor=F,header=T)
Error in file.choose() : file choice cancelled <<<<<< wrong dir
> mydata=read.csv(file.choose(),stringsAsFactor=F,header=T)
Error in file.choose() : file choice cancelled <<<<<<<<<<<< right dir
OTOH, if in the second command I had to run list.files(), I would get the correct list. And again, the first call file.choosewill behave unexpectedly.
TRACK. I again changed the current directory, on setwd("c:/Users")and tried list.files()and file.choose()and got the same pattern of results.
Why is he acting like this, or what I donβt see? I am using R 3.1.2 for Windows 7.
- EDIT added more details
From profile:
if (readline("Wanna pick a new working dir (by choosing a file)? y/xyz: ") == "y") {
try(setwd(dirname(file.choose())))
}
Using RGui
From sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base