Importing Data from Web in R

While working as a data scientist, you will often deal with data stored on the web. Typically you will have a URl for the data and you will make an HTTP request to fetch the data. The data itself can come in many formats, such as:

  • Files such as csv, delimited and excel files
  • Data available through APIs. The most popular format of data available through APIs is JSON
  • Data available in web tables inside web pages
  • And many more

In this lesson, we will look at how to import data in R from files and from APIs. While there are many packages and techniques to get data from the web, we will introduce some of these to you.

CSV Files

Earlier we used read.csv() from theutils package to import CSV files stored locally. The read.util() function is equally efficient to load data from csv files stored on the internet.

For this lesson, we will use a csv files which contains fundamentals of the top 100 stocks in the US. The file is available below:


If you paste this URL directly in a web browser, the browser will simply download the CSV file. To import the data from this file into R, you will need to pass the URL instead of the local file path as shown below:

#Import the csv file into variable 'top_stocks'
top_stocks <- read.csv("")
#print top-stocks

This content is for paid members only.

Join our membership for lifelong unlimited access to all our data science learning content and resources.

Lesson Resources

All Users