The first thing to do is to get the list of deputies, as you put it well in the original post:
library(bRasilLegis)
deputados <- obterDeputados()
After that, it's interesting to see what's inside the deputados
object. We do this through the str
command. I'm not going to put all his output here, because it's a bit extensive. I'm just going to stick to the first column of the object deputados
:
str(deputados)
'data.frame': 511 obs. of 16 variables:
$ ideCadastro : chr "81366" "141522" "195826" "196358" ...
Even because it is what interests us, since the ids of the deputies are there. What we need to do now is a loop that changes the delegate id within each call of the obterDetalhesDeputado
function. Just make a counter j
assume all 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 the information of each deputy.
The complete code looks like this:
dep <- list()
i <- 1
for (j in deputados$ideCadastro){
dep[[i]] <- obterDetalhesDeputado(ideCadastro=j,
numLegislatura="55", atuacao="comissoes")
i <- i+1
}