Skip to content
R for the Rest of Us Logo

Getting Started With R

Import Data

Transcript

Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.

Your Turn

  1. Create a new R script file and save it as import.R

  2. Add the line library(tidyverse) at the top of your R script file and run it to load the tidyverse package.

  3. Use the read_csv() function (not read.csv()) to import the penguins_data.csv file

Have any questions? Put them below and we will help you out!

You need to be signed-in to comment on this post. Login.

Bhumika Bhattacharya

Bhumika Bhattacharya • September 27, 2023

I copied the penguins data into my directory and it is also showing up in the 'files' section in the project but when I am running the code - read_csv("penguins_data.csv"), I am getting this output in the console :(

read_csv("penguins_data.csv") Error: 'penguins_data.csv' does not exist in current working directory ('C:/Users/rajab/OneDrive/Desktop/New project week 2').

Bhumika Bhattacharya

Bhumika Bhattacharya • September 27, 2023

This comment was supposed to go under "start a new project" my bad

Gracielle Higino

Gracielle Higino Coach • September 27, 2023

Hi Bhumika! It might be that you are not working on the same directory. Can you share on Discord a screenshot of your session? When this happens to me, I usually start running these codes on the terminal, just to quickly check if I'm working in the right place.

get_wd() # to get the exact directory I'm working on
dir() # to check the files on my current directory

You can inspect that using the posit interface too! For example, your working directory will be displayed on your console panel along with your R version.

Let me know if this helps and ping me on Discord to let me know how it went! =D

Libby Heeren

Libby Heeren Coach • September 28, 2023

I think we got it worked out in office hours! Just needed to have the project open in order for the code to run.

Samreen Chhabra

Samreen Chhabra • October 11, 2023

Hi! I'm getting this response for the library(tidyverse) code: Error: package or namespace load failed for ‘tidyverse’: .onAttach failed in attachNamespace() for 'tidyverse', details: call: NULL error: package or namespace load failed for ‘ggplot2’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]): there is no package called ‘utf8’

David Keyes

David Keyes Founder • October 11, 2023

For some reason, the tidyverse package didn't install correctly. It looks like this is because one package as part of the tidyverse didn't successfully install. Please run this in the console and then try again:

install.packages("utf8")

Let me know if that helps! Your other question should also be solved by this.

Samreen Chhabra

Samreen Chhabra • October 13, 2023

Hi, it worked! Thank you so much!

Sindhu Palle

Sindhu Palle • December 22, 2023

Hello, I got the same error and when I tried installing the package, it tells me package 'uft8' is not available for this version of R

David Keyes

David Keyes Founder • December 23, 2023

What version of R are you using? If it's older, you may need to update it before installing the package.

Sindhu Palle

Sindhu Palle • December 27, 2023

I am using Version 2023.12.0+369 (2023.12.0+369) on my MacOS Catalina 10.15.7

Sindhu Palle

Sindhu Palle • December 27, 2023

Nevermind I figured it out!

Sindhu Palle

Sindhu Palle • December 27, 2023

Nevermind I figured it out!

Samreen Chhabra

Samreen Chhabra • October 11, 2023

Also, for the read_csv("penguins_data.csv") code, this is what I get, despite working in getting-started-main. Any help would be appreciated, thank you!- read_csv("penguins_data.csv") Error in read_csv("penguins_data.csv") : could not find function "read_csv"

Charles Obiorah

Charles Obiorah • February 26, 2024

I'm excited I seem to getting along, though I have to do playback, and rewind many times. Furthermore I was going to wonder, if the sex and species variables are the same character, and age and weight are the same numericals (dbl), why did it limit those ones that were not shown

David Keyes

David Keyes Founder • February 27, 2024

I'm not quite sure I understand your question. Can you elaborate please?

Charles Obiorah

Charles Obiorah • February 28, 2024

I am sorry that I was not clear enough. I was wondering why sex was not loaded, despite its being a character. Also age not loaded and it is a dbl just like the weight that was loaded. Thank you

David Keyes

David Keyes Founder • February 28, 2024

What is happening is that RStudio only shows the variables that can fit on the screen. If you click on the object in the environment pane you can see all of the variables. Does that help?

SALIM SHEUNDA

SALIM SHEUNDA • March 5, 2024

Hey guys, I`m Salim Sheunda from Kenya,

I created a new R Script and saved it. Then added library(tidyverse) and clicked on run, got tidyverse packages. I then, used the read_csv (copy file path) and then run as instructed in the video but I got an error: Error in file(file, "rt") : cannot open the connection In addition: Warning message:In file(file, "rt") :cannot open file 'C:/Users/SHEUNDA SALIM/Desktop/Research Data/projo_data.csv': No such file or directory

What could be the problem?

David Keyes

David Keyes Founder • March 5, 2024

Are you sure you're working in a project? My guess is you're not. Can you please review this lesson and then confirm whether you're working in a project?

Lilly Kennedy

Lilly Kennedy • March 18, 2024

read_csv(penguins_data.csv) Error: object 'penguins_data.csv' not found

I am getting this error message even though I am working in the getting started project

Libby Heeren

Libby Heeren Coach • March 18, 2024

Hi, there! You'll need to use quotation marks around the file path, so try running: read_csv("penguins_data.csv")

Kendra Wilson

Kendra Wilson • March 21, 2024

Hi, I keep getting the error message Error: object 'penguins_data.csv' not found. I am working in the project and can import the data by clicking on the file name, but I cannot import using the read_csv function. Is there something else I need to do? Thanks.

Libby Heeren

Libby Heeren Coach • March 21, 2024

Hi, Kendra! Can you share the code that you ran? It sounds like R was looking for an object, not a file, which means you may have run the code without quotation marks around the file path. Try running read_csv("penguins_data.csv") instead of read_csv(penguins_data.csv).

Kendra Wilson

Kendra Wilson • March 21, 2024

Hi Libby, Yes that was the case. I figured out right after I sent the message. I did not have quotations. Thanks.

Tanwy Chowdhury

Tanwy Chowdhury • June 17, 2024

Hi! penguins.csv data is showing in my laptop folder but its not showing in the file section of r studio and whenever I am trying to import data, its showing file not found

David Keyes

David Keyes Founder • June 18, 2024

Are you working in an RStudio project? Please review the Projects lesson if you need help figuring out whether you are.

Charles Evans

Charles Evans • July 25, 2024

Pending approval

I must have missed something. Where do I find the penguins_data.csv file? When I run the program it says it cannot open the file/no such file or directory.

Charles Evans

Charles Evans • July 25, 2024

Pending approval

(I am in the Import Data lesson)

Charles Evans

Charles Evans • July 25, 2024

Pending approval

Please disregard. I had to go back to the Projects lesson and re-run the “usethis”, etc., instructions so the getting-started-materials installed correctly. Works good now.

Caroline Kypson

Caroline Kypson • August 28, 2024

Hi! I keep getting this error when I type in library(tidyverse): Error: package or namespace load failed for ‘tidyverse’: .onAttach failed in attachNamespace() for 'tidyverse', details: call: library(pkg, lib.loc = loc, character.only = TRUE, warn.conflicts = FALSE) error: there is no package called ‘ggplot2’

David Keyes

David Keyes Founder • August 28, 2024

Something happened when you tried to install the tidyverse package. Please run install.packages("tidyverse") (which will also install `ggplot2') and try again. Hopefully this solves it for you!

Caroline Kypson

Caroline Kypson • August 29, 2024

I am still getting the same error response after I re-installed tidyverse.

David Keyes

David Keyes Founder • August 29, 2024

Try running install.packages("ggplot2") and let me know if that works.

Caroline Kypson

Caroline Kypson • August 29, 2024

When I do that this message comes up:
There is a binary version available but the source version is later: binary source needs_compilation ggplot2 3.4.4 3.5.1 FALSE installing the source package ‘ggplot2’

trying URL 'https://cran.rstudio.com/src/contrib/ggplot2_3.5.1.tar.gz' Content type 'application/x-gzip' length 3604371 bytes (3.4 MB)

downloaded 3.4 MB

  • installing source package ‘ggplot2’ ... ** package ‘ggplot2’ successfully unpacked and MD5 sums checked ** using staged installation ** R ** data *** moving datasets to lazyload DB ** inst ** byte-compile and prepare package for lazy loading Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : there is no package called ‘munsell’ Calls: <Anonymous> ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart Execution halted ERROR: lazy loading failed for package ‘ggplot2’
  • removing ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/ggplot2’ Warning in install.packages : installation of package ‘ggplot2’ had non-zero exit status

The downloaded source packages are in ‘/private/var/folders/gy/lw4chfrd3jg6ghg8n46fhr2c0000gn/T/RtmpnQ9EIc/downloaded_packages’

So I'm still getting an error when I try to install ggplot2 and if I try to run library(tidyverse) the same error message about ggplot2 is still coming up.

David Keyes

David Keyes Founder • August 29, 2024

Hmm, let's try having you start from scratch. Run remove.packages("tidyverse") to uninstall the tidyverse. Then, try running install.packages("tidyverse") and let me know if that works.

Caroline Kypson

Caroline Kypson • August 30, 2024

I uninstalled then reinstalled and this message came up: Error in install.packages : Updating loaded packages

Restarting R session...

It then installed the tidyverse package and even said this under: also installing the dependency ‘ggplot2’

BUT if I try to run library(tidyverse) again I still am getting the same error: Error: package or namespace load failed for ‘tidyverse’: .onAttach failed in attachNamespace() for 'tidyverse', details: call: library(pkg, lib.loc = loc, character.only = TRUE, warn.conflicts = FALSE) error: there is no package called ‘ggplot2’

David Keyes

David Keyes Founder • August 30, 2024

This is very odd. Can you please run the function sessionInfo() and paste what is returned?

Caroline Kypson

Caroline Kypson • August 30, 2024

R version 4.2.3 (2023-03-15) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Ventura 13.5.1

Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets [6] methods base

loaded via a namespace (and not attached): [1] compiler_4.2.3 magrittr_2.0.3 tools_4.2.3
[4] tidyverse_2.0.0

David Keyes

David Keyes Founder • August 30, 2024

Could you try downloading the latest version of R and then reinstalling the tidyverse?

Caroline Kypson

Caroline Kypson • August 31, 2024

It worked! Thank you!

David Keyes

David Keyes Founder • September 2, 2024

Hurray!