Open In App

How to Read a CSV from URL into R?

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we are going to see how to read CSV files from URL using R Programming Language.

Method 1: Using Base R 

Here we are using read.csv() methods, which is an inbuilt function in R programming. This function is similar to Python because it read the CSV file and returns the data into dataframe.

Syntax: 

read.csv(URL)

Example: Read a CSV from URL 

R




# importing Data
/Annual-enterprise-survey/Annual-enterprise-survey-2020-\
financial-year-provisional/Download-data/annual-enterprise\
-survey-2020-financial-year-provisional-csv.csv')
 
# display top 5 row
head(data)


 Output:

Method 2: Using data.table

This package is capable to read the data from URL. Basically data.table is used for data manipulation operations such as subset, group, update, join, etc. This package contains fread() function that takes URL as input to get the job done.

Syntax: 

fread(URL)

Example: Read CSV from URL 

R




# importing Data
/Annual-enterprise-survey/Annual-enterprise-survey-2020-\
financial-year-provisional/Download-data/annual-enterprise\
-survey-2020-financial-year-provisional-csv.csv')
 
# display top 5 row
head(data)


 Output:

Example 2: Read CSV from URL

R




library(data.table)
 
# import data from URL
/Annual-enterprise-survey/Annual-enterprise-survey-2020-
financial-year-provisional/Download-data/annual-enterprise
-survey-2020-financial-year-provisional-csv.csv')
 
# Display first five rows
head(data)


 Output:



Last Updated : 29 Dec, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads