Code Monkey home page Code Monkey logo

Comments (3)

brilstl avatar brilstl commented on May 19, 2024

Hi Edwin,

Thank you for providing such an accessible package to retrieve CBS data with.

I had a question regarding the cbs_get_themes functionality. I wondered if I could filter the request on the basis of if a dataset withholds information about a particular city in the Netherlands?

This is the code that I use at the moment:

#-------------------------------Load packages-------------------------------------------------
library(cbsodataR)
library(dplyr)

#-------------------------------retrieve meta information CBS-----------------------------------

tbl.lijst <- cbs_get_toc(Language = "nl")

##-----------------------------------table description-------------------------------------------

DF <- tbl.lijst %>% 
  select(Identifier, ShortTitle)

tbl.lijst
##Store table description
Setwd(Output.meta)
Write.csv(Tbl.lijst[3:4], file = "lijst.csv")

And now I am wondering if I could also filter on a particular city/region besides filtering on the language of the dataset?

I would like to thank you in advance for answering my question!

Kind regards,

Tobias

from cbsodatar.

edwindj avatar edwindj commented on May 19, 2024

You're welcome!

Regarding your question:
the cbs_get_toc allows to filter on values of each of the columns. (just use <columnname>="<value>" in the function).

The table of contents however does not have a regions column, to do a direct filter, however the following script should help you get on your way:

library(cbsodataR)

# checking a table with "gemeente" data
meta <- cbs_get_meta(id ="70748ned")

# meta contains several meta data table including the RegioS or Gemeenten table
View(meta$Gemeenten) # find out which gemeente you want to select. 
# Note, the keys may contain spaces...

# Let us select the first "gemeente" Alkmaar
ALKMAAR <- meta$Gemeenten$Key[2]

# We can retrieve data for ALKMAAR
dat <- cbs_get_data(id = "70748ned", Gemeenten = ALKMAAR)

# or we can find out which tables contain ALKMAAR
toc <- cbs_get_toc(Language = "nl")

# takes a long time...
contains_alkmaar <- sapply(toc$Identifier, function(x){
  cat(".")
  meta <- cbs_get_meta(x)
  if (!is.null(meta$RegioS)){
    ALKMAAR %in% meta$RegioS$Key
  } else if (!is.null(meta$Gemeenten)){
    ALKMAAR %in% meta$Gemeenten$Key
  } else {
    FALSE
  }
})


toc_with_alkmaar <- toc[which(contains_alkmaar),]

from cbsodatar.

brilstl avatar brilstl commented on May 19, 2024

Hi Edwin,

Thank you for providing this piece of code. When I run the function it returns the following error:

Error during wrapup: Forbidden (HTTP 403). Failed to Client error: (403) Forbidden.

Basically indicating that the request that the function is asking will not be full-filled. Is there anyway to workaround this?

I tried putting Sys.sleep() in the function to slowly ask the server for information, but this did not solve the problem.

Appreciate the provided tips.

Kind regards,

Tobias

from cbsodatar.

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.