Error importing data . csv to Rstudio

Asked

Viewed 3,195 times

2

When I will import and create a file my data to the R it error...

I tried the following way:

 melipona <- paste(system.file(package="dismo"), "/ex/Melipona.csv", sep=";")


 melipona<-read.csv(melipona,header=TRUE,sep=";")

The following error appears:

Error in file(file, "rt") : cannot open the Connection In addition: Warning message: In file(file, "rt") : cannot open file 'C:/Users/N1na3/Documents/R/win-library/3.4/dismo/ex/Melipona.csv': No such file or directory

I’ve tried using the file.choose() but it just reads and does not create the file, then comes a part that it does not work. When I give the command list.files()g it appears my file, I used the getwd() to see if he was in the same place and is...

2 answers

4

The archive Melipona.csv is not located in the directory C:/Users/N1na3/Documents/R/win-library/3.4/dismo/ex/. I listed the contents of this directory on my computer and there are only two . csv files, called acaule.csv and bradypus.csv.

$ ls /Library/Frameworks/R.framework/Versions/3.4/Resources/library/dismo/ex/
total 1696
-rw-rw-r--  1 root  admin   191K Apr 21 21:02 acaule.csv
-rw-rw-r--  1 root  admin   487B Apr 21 21:02 bio1.grd
-rw-rw-r--  1 root  admin    70K Apr 21 21:02 bio1.gri
-rw-rw-r--  1 root  admin   487B Apr 21 21:02 bio12.grd
-rw-rw-r--  1 root  admin    70K Apr 21 21:02 bio12.gri
-rw-rw-r--  1 root  admin   487B Apr 21 21:02 bio16.grd
-rw-rw-r--  1 root  admin    70K Apr 21 21:02 bio16.gri
-rw-rw-r--  1 root  admin   487B Apr 21 21:02 bio17.grd
-rw-rw-r--  1 root  admin    70K Apr 21 21:02 bio17.gri
-rw-rw-r--  1 root  admin   486B Apr 21 21:02 bio5.grd
-rw-rw-r--  1 root  admin    70K Apr 21 21:02 bio5.gri
-rw-rw-r--  1 root  admin   488B Apr 21 21:02 bio6.grd
-rw-rw-r--  1 root  admin    70K Apr 21 21:02 bio6.gri
-rw-rw-r--  1 root  admin   486B Apr 21 21:02 bio7.grd
-rw-rw-r--  1 root  admin    70K Apr 21 21:02 bio7.gri
-rw-rw-r--  1 root  admin   487B Apr 21 21:02 bio8.grd
-rw-rw-r--  1 root  admin    70K Apr 21 21:02 bio8.gri
-rw-rw-r--  1 root  admin   477B Apr 21 21:02 biome.grd
-rw-rw-r--  1 root  admin    35K Apr 21 21:02 biome.gri
-rw-rw-r--  1 root  admin   4.0K Apr 21 21:02 bradypus.csv

Since I don’t have access to your computer, I can only speculate on a possible solution to your problem. Do the following:

1) Copy the file Melipona.csv somewhere known inside your computer. For example, a folder like Documents/Dissertation/Melipona/Analyze/

2) Inside Rstudio, go to the menu Session > Set Working Directory > Choose Directory . Navigate to the directory where the file Melipona.csv is stored.

inserir a descrição da imagem aqui

3) Turn the remote

melipona <- read.csv("Melipona.csv", header=TRUE, sep=";")

This should complete the reading of your file without major problems.

  • 1

    Confirmed in Windows 7. (The directory list above is Unix.) @Marcusnunes Also, in the command read.csv file name must be in quotes, please edit this, please.

  • Thanks for the help, Rui. I published the code without testing and reviewing, so this error appeared.

0

Run the command again:

Melipona <- read.csv(Melipona, header=TRUE,Sep=";")

Only this time try:

 melipona <- read.csv('melipona.csv', header=TRUE, sep=";")

I have that problem sometimes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.