Skip to content

Instantly share code, notes, and snippets.

View jthomasmock's full-sized avatar

Tom Mock jthomasmock

View GitHub Profile
#### ---------------------------------------------
## Edit via: RStudio > Tools > Edit Code Snippets
# Released under a MIT license
snippet fragment
[${1:text}]{.${2:type}}
snippet aside
[${1:text}]{.aside}
@jthomasmock
jthomasmock / rprofile-custom-prompt.R
Created September 29, 2021 21:38
An example of customizing your R prompt with the RProfile.
.First <- function(){
# adapted from: https://lapsedgeographer.london/2020-11/custom-r-prompt/
my_prompt <- function(...) {
git_branch <- suppressWarnings(system("git rev-parse --abbrev-ref HEAD",
ignore.stderr = TRUE, intern = TRUE))
if (length(git_branch) != 0) {
git_msg <- paste0(" @", git_branch)
library(tidyverse)
library(gt)
library(gtExtras)
library(nflreadr)
raw_qbr <- nflreadr::load_espn_qbr(league = "nfl", season = 2020:2021,
summary_type = "weekly")
qbr_df <- raw_qbr %>%
group_by(player_id) %>%
### Create a data dictionary from any data.frame input
### This is what I use for TidyTuesday each week!
# Tidyverse method
create_dictionary <- function(x) {
tibble::tibble(variable = names(x)) %>%
dplyr::mutate(
class = purrr::map(
x,
---
title: "Presentation"
format:
revealjs:
theme: [default, custom.scss]
---
## Slide 1
- List
``` r
library(dplyr)
# vector operation
chunk_vec <- function(chunk_size){
ceiling(seq_along(row_number())/chunk_size)
}
# operate on dataframe
chunk_df <- function(.data, chunk_size) {
@jthomasmock
jthomasmock / copilot_keyword.R
Created September 13, 2023 01:35
Solving the Keyword game with R, with a little help from RStudio and Copilot!
library(tidyverse)
library(stringr)
library(jsonlite)
# create a function to solve the Keyword game
# this game uses a 6 letter horizontal word at the
# intersection of 6 other words, where a missing letter from each of the vertical words
# accounts for one letter of the mystery 6 letter length horizontal word
# how to play
@jthomasmock
jthomasmock / guess_keyword.R
Created September 13, 2023 01:36
Guess the Keyword of the day with R!
library(tidyverse)
library(jsonlite)
library(shiny)
# get_json_data(date)
# score_letters(letters)
# read_keywords() on mac
# split_char(word) into words
# limit_words(words, str_length) to specific length and lower case
# top_words(word, words_in, top_n = 50) - combo of split_char, limit_words
ex_bold <- ggplot(mtcars, aes(disp, mpg)) +
geom_point() +
labs(
title = "<b>Fuel economy</b> vs. <i>engine displacement</i><br>
<span style = 'font-size:10pt'>Lorem ipsum *dolor sit amet,*
consectetur adipiscing elit, **sed do eiusmod tempor incididunt** ut
labore et dolore magna aliqua. <span style = 'color:red;'>Ut enim
ad minim veniam,</span> quis nostrud exercitation ullamco laboris nisi
ut aliquip ex ea commodo consequat.</span>",
x = "displacement (in<sup>3</sup>)",
@jthomasmock
jthomasmock / keyword-solver.R
Created August 17, 2023 15:15
Provide reasonable solutions to solve the Keyword game from WaPo.
library(tidyverse)
library(jsonlite)
library(shiny)
# get_json_data(date)
# score_letters(letters)
# read_keywords() on mac
# split_char(word) into words
# limit_words(words, str_length) to specific length and lower case
# top_words(word, words_in, top_n = 50) - combo of split_char, limit_words