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
}
Marcos, I’d wear one
sapply
instead offor
. For examplesapply(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.– Molx