R won't let me open saved file, says "no such file or directory" [duplicate] - r

This question already has answers here:
How to open CSV file in R when R says "no such file or directory"?
(16 answers)
Closed 2 years ago.
I just started using R a couple of weeks ago, I'm a new student in a research group that uses the program.
My supervisor gave me a file with the ending .idx to open in R and work on. I was eventually able to open it yesterday, but it took me 45 minutes! I thought I'd figured out how to do it yesterday, but again today R is telling me the file doesn't exist.
Yesterday I used list.files and file.exists and the file magically seemed to exist.
Please can anybody tell me how to reopen saved files from R back on to the console?

R won't let me open saved file, says “no such file or directory”
It sounds like you just don't have the working directory set to the directory that contains the file in question. Try typing getwd() at the R command prompt and see what path it returns. Chances are, it's not the path were your file is. In that case, you can either move the file into R's current working directory, or you can type setwd("/path/to/the/file") at an R command prompt to set the path (obviously, /path/to/the/file should be replaced with the path to the directory containing your file).

Related

Why do I keep getting an error when trying to import my file?

I'm trying to read csv file using R notebook and keep getting this error:
Error: 'Examples/data/starbucks.csv' does not exist in current
working directory ('C:/Users/c227466/Desktop')
I'm not sure what's going on!
This is the code I used:
starbucks <- read_csv("Examples/data/starbucks.csv")
starbucks
Your working directory is your desktop (which is not recommended). On your desktop, you should add a folder "Examples" and, in it, another folder "data" and your file there.

Unable to change directory in R Studio - problem with oneDrive

I am facing a problem while trying to change directory to read a csv in Rstudio.
When I type getwd() I get this as my directory:
C:/Users/giorg/OneDrive/Υπολογιστής/MSc_Data_Science_&_CI/Introduction to Statistical methods for Data Science/Coursework
So when I try to read my csv I get that error:
C:/Users/giorg/OneDrive/ÕðïëïãéóôÞò/MSc_Data_Science_&_CI/Introduction to Statistical methods for Data Science/Coursework/x.csv': No such file or directory
I tried to change through Global options > General but I still have oneDrive in my path
And when I try with setwd() I get :
setwd("C:/Users/giorg/OneDrive/Υπολογιστής/Giorgos")
Error in setwd("C:/Users/giorg/OneDrive/<U+03A5>p<U+03BF><U+03BB><U+03BF><U+03B3><U+03B9>st<U+03AE><U+03C2>/Giorgos")
cannot change working directory
Any suggestions about what should I do?
I had the same problem at some point. When I tried to change the directory I got the same error. In my case, the problem started when I changed the language of my computer. The file which I wanted to use as directory named in Greek language and after I turned my computer to English, R couldn't recognize it.
The problem solved when I renamed the file with English characters.

Read.csv returns an error: Cannot Open Connection [duplicate]

This question already has answers here:
read.table() and read.csv both Error in Rmd
(5 answers)
Closed 5 years ago.
I have a strange problem. I want to read a CSV file, and I am perfectly able to do so in my console, but when I do the exact same line in my R markdown file, I get the error:
Error in file(file, "rt") : cannot open the connection
Why can I read the file in the console but not in the R Markdown file?
Working directory of your Rmd differs from the ones of your R console. You should explicitly define the path to your file in the Rmd to avoid the error.
Another option would be moving your csv files to the folder that your markdown is existed.
In sum, You need to consider where the Rmd is, where the current directory of your console is and where your files are. If necessary move the files or change the directory or use explicit path.
Using getwd() you can get the current working directory for your markdown or your console.

Error processing gps file in R script

Newbie R question: I have been trying to test the R script posted in FlowingData, but the script spit out the following error:
Error: XML content does not seem to be XML: 'NA'
I am running R on my windows box, with the .gpx files in the same directory as the script. Any help is appreciated.
Not sure if you ever found the answer to this or not, but the XML error relates to the fact that R does not know where your .gpx files are. While the FlowingData script indicates that the script will work if the .gpx files are in the same folder as your saved R script copy/pasted from FlowingData, that is not true. You must also set your working directory to this path as well, then R will see your .gpx files. If you FlowingData R script file and .gpx files are in: C:\Users\leon\Documents\R then add this line under the library(plotKML) line to set your working directory: setwd("C:\\Users\\leon\\Documents\\R")
Another word of note, make sure you only use the RunKeeper gpx files for a fairly small geographic area or the plotted data will be insanely small.

How to change .Rprofile location in RStudio

I am working with a "factory fresh" version of RStudio on Windows 7. R is installed under C:/Program Files which means the default libraries are stored here, and the two locations contained in .libPaths() on startup are both within this folder.
I want to work with another R library (igraph). Since the C:\Program Files folder is write-protected, I have set up another area to work in: C:\Users\nick\R and installed the igraph library in C:\Users\nick\R\library. I can manually add this location to the .libPaths() variable and use the library with no problems.
However, my problem is getting RStudio to automatically add this location to the .libPaths() variable on startup. I read that I could add the relevant command to my .Rprofile file - but I couldn't find any such file (presumably they are not automatically created when RStudio is installed). I then created a file called .Rprofile containing only this command. This only seemed to work when the .Rprofile file was saved in C:\Users\nick\Documents (which is the path stored in both the R_USER and HOME environmental variables). What I would like is to have the .Rprofile file stored in C:\Users\nick\R.
I have read all the information in ?Startup and it talks about where to store commands that run on startup. But I just can't make this work. For example there seems to be no way to change the location of the home directory without reading a file stored in the home directory. I don't seem to have any .Renviron files and creating these myself doesn't seem to work either.
I would really appreciate an answer in simple terms that explains how I could go about changing where the .Rprofile file is read from.
In Windows, you set the R_USER profile by opening up a command line and running:
SETX R_PROFILE_USER "C:/.../.Rprofile"
Where (obviously) the path is the path to your desired .Rpofile. In R, you can check that it worked:
Sys.getenv("R_PROFILE_USER")
Should return the path you specified. Note that you likely need to have all R sessions closed before setting the R_USER variable.

Resources