Skip to content

Instantly share code, notes, and snippets.

View avallecam's full-sized avatar
🎯
Focusing

Andree Valle Campos avallecam

🎯
Focusing
View GitHub Profile
@bquilty25
bquilty25 / gist:1cb5c352a25a9af253646d1fc745cb4b
Created January 29, 2024 10:51
Accessing OpenAI API from R
library(httr)
library(jsonlite)
api_key <- "sk-XXX" # Set your OpenAI API key (don't publish anywhere public!)
base_url_openai <- "https://api.openai.com/v1"
openai_call <- function(prompt) {
request_url <- paste0(base_url_openai, "/chat/completions")
library(tidycensus)
library(ggiraph)
library(tidyverse)
library(patchwork)
vt_income <- get_acs(
geography = "county",
variables = "B19013_001",
state = "VT",
year = 2019,
@deanmarchiori
deanmarchiori / complete.r
Created August 13, 2020 06:06
Turning implicit missing values into explicit missing values.
# tidyr::complete() & tidyr::full_seq() -----------------------------------
# Turning implicit missing values into explicit missing values.
# Bonus: Filling in gaps in a date range
library(tidyr)
library(tibble)
library(dplyr)
# Making up some observations from two weather stations.
@avallecam
avallecam / coalesce.R
Last active February 12, 2020 17:43
R: resumir respuestas de opción múltiple
``` r
library(tidyverse)
library(naniar)
# more on naniar: https://cran.r-project.org/web/packages/naniar/vignettes/replace-with-na.html
#create foo dataset
foo <- tibble(xA=c(1,rep(NA,2),2),
xB=c(rep(NA,2),5:4),
xC=2:5) %>%
mutate_all(.funs = as.double)
@benmarwick
benmarwick / rotate-axis-labels-ggplot2.R
Last active March 30, 2024 08:00
I can never remember how to rotate the x-axis labels with ggplot2: theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
# Adapted from https://stackoverflow.com/a/7267364/1036500 by Andrie de Vries
# This is it: theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
library(ggplot2)
td <- expand.grid(
hjust=c(0, 0.5, 1),
vjust=c(0, 0.5, 1),
angle=c(0, 45, 90),
@jesperronn
jesperronn / docx2md.md
Last active November 21, 2023 12:49 — forked from aembleton/docx2md.md
Convert a Word Document into MD

Converting a Word Document to Markdown in One Move

The Problem

A lot of important government documents are created and saved in Microsoft Word (*.docx). But Microsoft Word is a proprietary format, and it's not really useful for presenting documents on the web. So, I wanted to find a way to convert a .docx file into markdown.

Installing Pandoc

On a mac you can use homebrew by running the command brew install pandoc.

The Solution

@jefferys
jefferys / roxygen2MultiFunctionDocumentation.gist.R
Created June 21, 2015 17:29
R function documentation with roxygen2 - multiple functions
#===================================================
# Demo multi-function roxygen2 - three ways to do it
#===================================================
# This shows how things do work, including wierd corner cases, not
# how they should be done. Most of the information comes from
# http://r-pkgs.had.co.nz/man.html
#====================================================
# Demo multi-function roxygen2 page using @describeIn
@Pakillo
Pakillo / word-character-count-Rstudio.md
Last active June 25, 2020 21:24
Count words and characters in Rstudio

As far as I know Rstudio does not count words or characters at the moment, which would be useful particularly when writing Rmarkdown.

This is a quick shortcut using word_count and character_count functions from qdap package. See below for two wrapper functions that simplify their use.

library("qdap")

Just select and copy the text to the clipboard and then run in the console: