Skip to content

Instantly share code, notes, and snippets.

View sergiospagnuolo's full-sized avatar
🐕‍🦺

Sérgio Spagnuolo sergiospagnuolo

🐕‍🦺
View GitHub Profile
@fernandobarbalho
fernandobarbalho / gist:40f7e6c0cf925065e21084062e5ad513
Last active August 9, 2022 20:55
script para leitura e tratamento de tabela do ibama sobre oleamento de praias do NE
library(tabulizer)
library(dplyr)
setwd("~/GitHub/oleogate/data")
#Extrai tabelas do arquivo pdf.
#Esse arquivo foi baixado do seguinte link
# https://politica.estadao.com.br/blogs/estadao-verifica/wp-content/uploads/sites/690/2019/10/Ibama.pdf
#A tabela é extraída para um arquivo csv de forma a poder trabalhar melhor questões de encoding
tabulizer::extract_tables("ibama.pdf", output = "csv",outdir = getwd())
@fernandobarbalho
fernandobarbalho / script_indice_FIRJAN.R
Last active May 25, 2021 17:33
Script para cálculo do índice de autonomia da FIRJAN usando o pacote rsiconfi
# install.packages("devtools")
devtools::install_github("tchiluanda/rsiconfi")
library(rsiconfi)
library(dplyr)
library(tidyr)
###########Trabalhando as despesas
#Monta um vetor com todos os códigos de UFs do Brasil
@sergiospagnuolo
sergiospagnuolo / atlas_connect.R
Last active October 23, 2020 16:53
Acessando API do Atlas da Notícia via R
# Força o encoding para UTF-8, default do banco de dados
# Colaboração de Sérgio Spagnuolo (sergio@voltdata.info)
# Programa acessar a API do Atlas da Notícia (https://www.atlas.jor.br/)
# É necessário antes se cadastrar, veja como aqui: https://www.atlas.jor.br/plataforma/utilizarAPI/
library(httr)
library(jsonlite)
# Puxa os dados da sua credencial
token = content(
@fernandobarbalho
fernandobarbalho / ETL_pensionistas.R
Created January 14, 2020 15:05
ETL para tratar dados de pensionsitas
library(readr)
library(dplyr)
PENSIONISTAS_112019 <- read_delim("Data/PENSIONISTAS_112019.csv",
";", escape_double = FALSE, locale = locale(decimal_mark = ",",
grouping_mark = ".", encoding = "LATIN1"),
trim_ws = TRUE)
PENSIONISTAS_122019 <- read_delim("Data/PENSIONISTAS_122019.csv",
";", escape_double = FALSE, locale = locale(decimal_mark = ",",
@fernandobarbalho
fernandobarbalho / get_last_covid_rt.r
Last active April 16, 2020 19:15
Function that returns the last estimated rt from a time series of cummulative number of COVID-19 cases
#based on this method: https://github.com/k-sys/covid-19/blob/master/Realtime%20R0.ipynb
# In fact it is a translation from python to R of some parts of the code explained in the link above.
get_last_covid_rt<- function(df_days_case){ #this dataset must have a structre with a collumn no_cases (accumulated number of cases on a given sequence day)
#smooth the data
x <- 1:NROW(df_days_case)
y<-df_days_case$no_cases
@lgelape
lgelape / stopwords_pt.R
Last active March 7, 2023 18:45
Create a dataset with stopwords in Portuguese (from Stopwords ISO, tidytext and tm packages)
### STOPWORDS IN PORTUGUESE
## Create a unique dataset from several datasets with stopwords in Portuguese
# Lucas Gelape
# Packages
library(dplyr)
library(stringi)
library(readr)
@fernandobarbalho
fernandobarbalho / get_cofog_data.r
Created July 14, 2021 15:02
Extração de dados do cofog diretamente da base de dados abertos do Tesouro Transparente
library(readxl)
library(ckanr)
library(purrr)
ckanr::package_search()
package<- ckanr::package_show(id= "22d13d17-bf69-4a1a-add2-25cc1e25f2d7",
url= "https://www.tesourotransparente.gov.br/ckan") #busca todos os dados do dataset que se refere aos dados de COFOG
@jlomako
jlomako / openai_in_R.R
Created October 27, 2022 15:34
use GPT-3 in R with the OpenAI API
#####################################################
# Use GPT-3 in R with the OpenAI API. You need to install the reticulate package.
# Additionally, an API key is required that must be saved in a separate file, called .openaikey
# Get your API key here: https://openai.com/api/
#####################################################
# install.packages("reticulate") # run only once
library(reticulate)
# create python env