0

I am trying to load DTA file into R. How do I get a file to exist that R tells me doesn't exist when I am trying to load it? I have also tried loading an SAV file through SPSS in the import dataset function in R but I get the same error message that the file does not exist.

install.packages('haven')
library(haven)
data<-read_dta('C:/Users/myname/Downloads/anes_timeseries_2016_dta%20(4).zip')

in the console, after I try to run it, I get

> data<-read_dta('C:/Users/myname/Downloads/anes_timeseries_2016_dta%20(4).zip')
Error: 'C:/Users/myname/Downloads/anes_timeseries_2016_dta%20(4).zip' does not exist.
> install.packages("haven")
trying URL 'https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.1/haven_2.5.1.tgz'
Content type 'application/x-gzip' length 1068665 bytes (1.0 MB)
==================================================
downloaded 1.0 MB


The downloaded binary packages are in
    /var/folders/kb/nlv1ctzx5ssb3ncqkbts9zr80000gn/T//RtmpJWiKhR/downloaded_packages

I see that the error message says

'C:/Users/myname/Downloads/anes_timeseries_2016_dta%20(4).zip' does not exist

But I'm trying to get it to exist. Ho do I make it exist as I try to download it? It's in my downloads on my laptop. So, how do I get

'C:/Users/myname/Downloads/anes_timeseries_2016_dta%20(4).zip'
r2evans
  • 141,215
  • 6
  • 77
  • 149
Irene
  • 11
  • 2
  • 2
    What does `list.files("C:/Users/myname/Downloads/")` return? Make sure the file name matches exactly. The "%20" part seems suspicious. – MrFlick Nov 22 '22 at 20:34
  • *"How do I get"* ... where are you finding it to be able to download it? You're asking about how to read something in R when it isn't apparent how you've downloaded it or verified that it downloaded successfully. – r2evans Nov 22 '22 at 20:49
  • It's on my laptop, in downloads. But I don't get how to get it into R from my downloads. I've always done CSV files, not a DTA. I install the aforementioned packages and the data does not load. – Irene Nov 22 '22 at 21:41
  • 1
    It's there, but what's its exact name? Note that it has nothing to do with the file format. What is returned by `file.exists('C:/Users/myname/Downloads/anes_timeseries_2016_dta%20(4).zip')`? (well, replacing `myname` as I assume you masked your real name) –  Nov 22 '22 at 23:13
  • 1
    For the record, just tried a [random dta file](https://www.stata-press.com/data/r11/machine.dta), zipped, with a name similar to your: everything works fine. You might want to really double check the full name, that you are looking in the right directory, and show here what was asked: result of `list.files` and `file.exists`. –  Nov 22 '22 at 23:32
  • it returns [1] False – Irene Nov 28 '22 at 14:06

0 Answers0