This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dir_size <- function(x){ | |
purrr::map_dfr(x, purrr::possibly(~{ | |
system(glue::glue("du -s {.x}"), intern = T) |> | |
stringr::str_split_1("\\s+") |> | |
setNames(c("tamanho","diretorio")) | |
},NULL)) |> | |
dplyr::mutate(tamanho = as.numeric(tamanho)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ibge_ftp <- paste0("https://ftp.ibge.gov.br/Trabalho_e_Rendimento/", | |
"Pesquisa_Nacional_por_Amostra_de_Domicilios_anual/", | |
"microdados/") | |
r1 <- ibge_ftp |> | |
httr2::request() |> | |
httr2::req_perform() |> | |
httr2::resp_body_html() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Procura a palavra ou frase do segundo vetor que melhor | |
#' se aproxima do primeiro. Particularmente útil para | |
#' corrigir nomes de municípios. | |
#' | |
#' @param x Vetor de strings de referência. | |
#' @param y Vetor de strings a serem buscados. | |
#' | |
#' @return vetor com as strings de y próximos | |
#' de x. | |
#' @export |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Baixa e atualiza versão do chromedriver com a versão do chrome. | |
#' | |
#' @return OK! | |
#' @export | |
#' | |
compatibilizar_chromever <- function(){ | |
driver <- binman::list_versions("chromedriver") |> | |
unlist() |> | |
utils::tail(1) |> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Convertion to title case with lower case for some classes of words. | |
#' | |
#' In written Portuguese, when converting to title case, it is not usual | |
#' to keep in title case some words, like prepositions, conjunctions, | |
#' articles and some kinds of pronouns. This functions locates those | |
#' cases and converts them to lower case. | |
#' | |
#' @param string vector of characters to be converted to title case | |
#' but with connector words (one-word prepositions and conjunctions) | |
#' and articles (both definite and indefinite) and some pronouns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Converts PostgreSQL table from long to wide format | |
#' | |
#' @param conn Connection | |
#' @param tbl Table | |
#' @param new_tbl Optional. It creates a new table in the database | |
#' instead of importing it to R | |
#' @param id_cols String vector with the name of columns to be used as identities | |
#' @param names_from Column whose values will become variables | |
#' @param values_from Column whose values will populate the new variables | |
#' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Conta tokens de textos com base em modelos da OPENAI | |
#' | |
#' @param x Vetor de textos | |
#' @param modelo Modelo a ser utilizado. | |
#' | |
#' @details Para usar esta função você tem de ter instalado o pacote | |
#' tiktoken do Python, o qual será chamado via reticulate. | |
#' | |
#' @return Vetor com quantidade de tokens em cada texto. | |
#' @export |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
msql_colacao <- function(conn, schema = NULL, table = NULL, ...){ | |
dots <- rlang::ensyms(...) |> | |
purrr::map_chr(rlang::as_string) | |
### Verifica se as colunas existem | |
q <- glue::glue_sql("select top 0 * from {`schema`}.{`table`}", .con = conn) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import openai | |
import tiktoken | |
from scipy import spatial | |
import pandas as pd | |
df=pd.read_csv('./data/oscars.csv') | |
print(df.head()) | |
df=df.loc[df['year_ceremony'] == 2023] | |
df=df.dropna(subset=['film']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from zeep import Client | |
import xmltodict | |
import json | |
from dotenv import load_dotenv | |
import os | |
import getpass | |
def consultar_processo( | |
usuario= None, |
NewerOlder