installed.packages("wbsets")
##      Package LibPath Version Priority Depends Imports LinkingTo Suggests
##      Enhances License License_is_FOSS License_restricts_use OS_type Archs
##      MD5sum NeedsCompilation Built
library (wbstats)

Get the metadata

meta <- wb_cache()
names(meta)
## [1] "countries"     "indicators"    "sources"       "topics"       
## [5] "regions"       "income_levels" "lending_types" "languages"

Write to a csv

write.csv(meta$countries, "countries.csv")
write.csv(meta$topics, "topics.csv")

Search indicator using patterns

wb_search("population")
## # A tibble: 3,967 × 3
##    indicator_id         indicator                               indicator_desc  
##    <chr>                <chr>                                   <chr>           
##  1 1.0.HCount.1.90usd   Poverty Headcount ($1.90 a day)         The poverty hea…
##  2 1.0.HCount.2.5usd    Poverty Headcount ($2.50 a day)         The poverty hea…
##  3 1.0.HCount.Mid10to50 Middle Class ($10-50 a day) Headcount   The poverty hea…
##  4 1.0.HCount.Ofcl      Official Moderate Poverty Rate-National The poverty hea…
##  5 1.0.HCount.Poor4uds  Poverty Headcount ($4 a day)            The poverty hea…
##  6 1.0.HCount.Vul4to10  Vulnerable ($4-10 a day) Headcount      The poverty hea…
##  7 1.0.PGap.1.90usd     Poverty Gap ($1.90 a day)               The poverty gap…
##  8 1.0.PGap.2.5usd      Poverty Gap ($2.50 a day)               The poverty gap…
##  9 1.0.PGap.Poor4uds    Poverty Gap ($4 a day)                  The poverty gap…
## 10 1.1.HCount.1.90usd   Poverty Headcount ($1.90 a day)-Rural   The poverty hea…
## # ℹ 3,957 more rows

Download data using indicator

pop <- wb_data("SP.POP.TOTL")
write.csv(pop, "population.csv")

Quantmod API

# install.packages("quantmod")
library(quantmod)
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
getSymbols(c("MSFT", "BAC", "HOOD", "TSLA"), src="yahoo")
## [1] "MSFT" "BAC"  "HOOD" "TSLA"

Plot the Data

plot(MSFT$MSFT.Close)

plot(HOOD$HOOD.Close)

plot(BAC$BAC.Close)

plot(TSLA$TSLA.Close)

# Save the stock data as a CSV

write.zoo(TSLA, "TSLA.csv", sep=",")