Giter Club home page Giter Club logo

Comments (4)

DavisVaughan avatar DavisVaughan commented on June 8, 2024 1

@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.

DavisVaughan avatar DavisVaughan commented on June 8, 2024

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.

thistleknot avatar thistleknot commented on June 8, 2024

image

from fredr.

thistleknot avatar thistleknot commented on June 8, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.