Comments (4)
@thistleknot I'm happy to hear that you found a solution that works for you, however, I think that fredr should probably stick to just the API endpoints without too much additional work on top of it, so we probably won't add this. Thanks for detailing your solution though, in case anyone else needs this!
from fredr.
That function isn't exported, so im not really sure what it actually does.
fredr is really designed for you to use it in conjunction with the FRED site. For example, they have a category section
https://fred.stlouisfed.org/categories/
Clicking on Money and Banking -> Exchange Rates -> Daily Rates, I can see all the daily rate series and can use their drop down to sort by popularity.
At the top in the URL, I can see the category id for Daily Rates is 94, which I can use in more fredr functions if I want.
You can incrementally get your way there with fredr_category_children()
, but I still needed to reference the website to figure out the path to get to the Daily Series category.
library(fredr)
#> Warning: package 'fredr' was built under R version 4.0.2
fredr_category_children(0)
#> # A tibble: 8 x 3
#> id name parent_id
#> <int> <chr> <int>
#> 1 32991 Money, Banking, & Finance 0
#> 2 10 Population, Employment, & Labor Markets 0
#> 3 32992 National Accounts 0
#> 4 1 Production & Business Activity 0
#> 5 32455 Prices 0
#> 6 32263 International Data 0
#> 7 3008 U.S. Regional Data 0
#> 8 33060 Academic Data 0
fredr_category_children(32991)
#> # A tibble: 7 x 4
#> id name parent_id notes
#> <int> <chr> <int> <chr>
#> 1 22 Interest Rates 32991 <NA>
#> 2 15 Exchange Rates 32991 <NA>
#> 3 24 Monetary Data 32991 <NA>
#> 4 46 Financial Indicat… 32991 <NA>
#> 5 23 Banking 32991 <NA>
#> 6 32360 Business Lending 32991 <NA>
#> 7 32145 Foreign Exchange … 32991 "In addition to the listed daily intervent…
fredr_category_children(15)
#> # A tibble: 5 x 4
#> id name parent_id notes
#> <int> <chr> <int> <chr>
#> 1 94 Daily Rates 15 "Effective January 1, 2009, the Federal Reser…
#> 2 95 Monthly Rates 15 <NA>
#> 3 32219 Annual Rates 15 <NA>
#> 4 105 Trade-Weighted… 15 <NA>
#> 5 158 By Country 15 <NA>
fredr_category_series(94, order_by = "popularity")[c(1, 4, 5, 6)]
#> # A tibble: 35 x 4
#> id title observation_sta… observation_end
#> <chr> <chr> <chr> <chr>
#> 1 TWEXEME… Trade Weighted U.S. Dollar Index: … 2006-01-01 2019-01-01
#> 2 TWEXAFE… Trade Weighted U.S. Dollar Index: … 2006-01-01 2019-01-01
#> 3 TWEXBGS… Trade Weighted U.S. Dollar Index: … 2006-01-01 2019-01-01
#> 4 DEXSLUS Sri Lanka / U.S. Foreign Exchange … 1973-01-02 2020-11-25
#> 5 TWEXEME… Trade Weighted U.S. Dollar Index: … 2006-01-01 2020-10-01
#> 6 DTWEXO Trade Weighted U.S. Dollar Index: … 1995-01-04 2019-12-31
#> 7 DEXDNUS Denmark / U.S. Foreign Exchange Ra… 1971-01-04 2020-11-25
#> 8 TWEXAFE… Trade Weighted U.S. Dollar Index: … 2006-01-01 2020-10-01
#> 9 DEXUSNZ U.S. / New Zealand Foreign Exchang… 1971-01-04 2020-11-25
#> 10 DEXVZUS Venezuela / U.S. Foreign Exchange … 1995-01-02 2020-11-25
#> # … with 25 more rows
I think it would be rather hard to show all recursive children of a node at once if that is what you are asking for
from fredr.
from fredr.
updated script
library(fredr)
fredr_set_key("getyourown")
recursive.categories <- function(x) {
#parent <- fredr_category(32266)
Sys.sleep(.5)
parent <- fredr_category(x)
Sys.sleep(.5)
series <- fredr_category_series(x)
Sys.sleep(.5)
children <- fredr_category_children(category_id = parent$id)
print(parent)
print(series)
if (length(children) == 0) {
p <- cbind(parent$id,parent$name)
names(p) <- iconv(paste(parent$id,parent$name), from="UTF-8", to="UTF-8", sub="")
#names(p) <- paste(parent$id,parent$name)
#return (p)
if(nrow(series)!=0)
{
#set <- list(parent,series)
#names(set) <- c(iconv(paste(parent$id,parent$name,"info"), from="UTF-8", to="UTF-8", sub=""),iconv(paste(parent$id,parent$name,"series"), from="UTF-8", to="UTF-8", sub=""))
set <- list(series)
names(set) <- c(iconv(paste(parent$id,parent$name,"series"), from="UTF-8", to="UTF-8", sub=""))
} else
{
#set <- parent
}
return(set)
}
else {
c <- (lapply(children[["id"]], function(y)
{
Sys.sleep(.5)
print(y)
recursive.categories(y)
}))
names(c) <- iconv(paste(children$id,children$name), from="UTF-8", to="UTF-8", sub="")
#names(c) <- paste(children$id,children$name)
#set <- list(parent,c,series)
#set <- list(c,series)
if(nrow(series)!=0)
{
#set <- list(parent,c,series)
#names(set) <- c(iconv(paste(parent$id,parent$name,"info"), from="UTF-8", to="UTF-8", sub=""),iconv(paste(parent$id,parent$name,"children"), from="UTF-8", to="UTF-8", sub=""),iconv(paste(parent$id,parent$name,"series"), from="UTF-8", to="UTF-8", sub=""))
set <- list(c,series)
names(set) <- c(iconv(paste(parent$id,parent$name,"children"), from="UTF-8", to="UTF-8", sub=""),iconv(paste(parent$id,parent$name,"series"), from="UTF-8", to="UTF-8", sub=""))
} else
{
#set <- list(parent,c)
#names(set) <- c(iconv(paste(parent$id,parent$name,"info"), from="UTF-8", to="UTF-8", sub=""),iconv(paste(parent$id,parent$name,"children"), from="UTF-8", to="UTF-8", sub=""))
set <- list(c)
names(set) <- c(iconv(paste(parent$id,parent$name,"children"), from="UTF-8", to="UTF-8", sub=""))
}
return(set)
#return(c)
}
}
sets <- recursive.categories(0)
#sets <- recursive.categories(32266)
#sets <- recursive.categories(32998)
View(sets)
store <- as.Node(sets)
ToDataFrameTree(store)
from fredr.
Related Issues (20)
- Unable to Install (Broken Dependency?) HOT 2
- Support for FRED Maps HOT 3
- Option to select Seasonally Adjusted Observation HOT 1
- upper bound too low for limit in fredr_category_series() HOT 3
- Pagination HOT 1
- Encoding error with fredr_series_observations HOT 11
- Better test environment for API requests HOT 3
- CRAN issues HOT 25
- Removed from CRAN? HOT 2
- Fredr can't return a legit series_id HOT 3
- Getting fredr back on CRAN HOT 24
- Release fredr 2.0.0
- This likely isn't an issue with your code, but something to be wary of HOT 3
- Trouble downloading multiple FRED series HOT 5
- fredr() and parameter vintage_dates HOT 5
- M2 not FedFunds
- Release fredr 2.1.0 HOT 1
- fredr appears to be completely broken on my R setup HOT 6
- Capture multiple series simultaneously? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fredr.