Skip to content

Reading Files in R: RStudio, Google Colab, and Posit.cloud

License

Notifications You must be signed in to change notification settings

Fausford/Reading_Files_R

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Reading Files in R: RStudio, Google Colab, and Posit.cloud

This guide covers how to read data files in R across different environments, including:

  • RStudio (Desktop & Server)

  • Google Colab (with R kernel)

  • Posit.cloud

We’ll cover:

  • File types (.csv, .xlsx) and required packages

  • Reading from local machine

  • Reading from a different directory

  • Reading from an online source (e.g., GitHub)

Reading CSV and Excel Files in R

CSV Files

A CSV (Comma-Separated Values) file stores data as plain text, where each row represents one record and each value is separated by a comma.

They are lightweight, portable, and can be opened in many programs including Excel, Notepad, R, and Python.

CSV files are commonly used for data exchange because they are simple and widely supported.

When working with CSV files in R, you can read them from:

  1. The same directory as your project or script.

  2. A different folder on your computer using the full file path.

  3. An online source, such as a file hosted on GitHub, using its direct link.

Excel Files

Excel files have extensions .xls or .xlsx. They can store multiple sheets, formatting, formulas, and charts, but R will only import the raw tabular data.

When working with Excel files in R, you can:

Read data from the default first sheet.

  1. Specify a sheet name or number to read from a particular sheet.

  2. Read from files stored locally or from a direct download link online.

Good Practices for Both File Types

  1. Keep your data files organized in a dedicated data folder inside your project.

  2. Always check your current working directory to ensure R is looking in the right place.

  3. Use relative paths for file locations when possible so your project is portable.

  4. After importing, always inspect the first few rows, the structure, and the summary statistics of your dataset to confirm it loaded correctly.

About

Reading Files in R: RStudio, Google Colab, and Posit.cloud

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published