bRasilLegis [ command "get DetailsDeputed"]

Asked

Viewed 79 times

5

I need to collect the data of the deputies who were present in committees, positions, etc. However, I can only do this with one deputy at a time. It’s possible I can choose them all at once?

library(bRasilLegis)
dep <- obterDetalhesDeputado(ideCadastro = '81366' , numLegislatura = "55", 
atuacao = "comissoes")

The argument ideCadastro is where I should put the deputy’s code (in the above case is the '81366'), which is obtained by means of the code deputados <- obterDeputados().

It is possible to put all codes at once?

1 answer

4


The first thing to do is get the list of deputies, as you well put in the original post:

library(bRasilLegis)

deputados <- obterDeputados()

After that, it’s interesting to see what’s inside the object deputados. We do this through command str. I’m not going to put all his output here, because it’s a little long. I’m going to stick to just the first column of the object deputados:

str(deputados)
'data.frame':   511 obs. of  16 variables:
 $ ideCadastro    : chr  "81366" "141522" "195826" "196358" ...

We are interested in it, since the Members' ids are there. What we need to do now is a loop that changes the member’s id within each function call obterDetalhesDeputado. Just make an accountant j assume all the values of deputados$ideCadastro.

We also need to save these results in one place. I chose to save to a list, called dep.

Finally, the position within each element of the list should vary when the ids of the deputies vary. For this I created a second counter called i, which I will update manually after downloading each Member’s information.

The whole code goes like this:

dep <- list()

i <- 1
for (j in deputados$ideCadastro){
    dep[[i]] <- obterDetalhesDeputado(ideCadastro=j, 
    numLegislatura="55", atuacao="comissoes")
    i <- i+1
}
  • 1

    Marcos, I’d wear one sapply instead of for. For example sapply(deputados$ideCadastro, function(j) {...}). In addition to being more idiomatic, it is faster than its alternative, as it grows a list, which is a very slow operation in R, since every change the list is copied again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.