Importing data into R


#1

How to import data into R -

Error: 'UKgas.csv' does not exist in current working directory ('C:/Users/User/Documents')

Referred here from support.rstudio.com


#2

@jamaliah
Can I see the full command when you import data?
(I assume your file's name is correctly spelled.)

Option 1: You can use file.choose() function to import data.
df = file.choose()
When you hit Enter/Return, you will be prompted to a new screen then from there, you can choose the file you want to import .

Option 2:
On the top of the R Screen, choose:

Session -> Set Working Directory -> Choose Directory...

You will be able to set up the working directory. When you are done setting this up, you can do this:

df = read.csv('UKgas.csv', header = TRUE) # if you want the headers

I hope this helps!


#3

library(readr)

UKgasDF <- read_csv("UKgas.csv")
Error: 'UKgas.csv' does not exist in current working directory ('C:/Users/User/Documents').
View(dataset)
Error in View : object 'dataset' not found


#4

@blackish952
Have you tried the two options I mentioned above?
Also, even if you loaded "UKgas.csv" successfully, View(dataset) would not return anything.
Where do you declare dataset object? Nowhere!
You may want to view

View(UKgasDF)

#5

The file isn't in the same directory as R's working directory. You either need to supply an absolute or relative file path.

For example, if UKgas.csv is in the directory C:/Users/User/Documents/MyProject/data, then either of these two snippets should work:

# absolute
UKgasDF <- read_csv("C:/Users/User/Documents/MyProject/data/UKgas.csv")
# relative
UKgasDF <- read_csv("MyProject/data/UKgas.csv")