Skip to content

Instantly share code, notes, and snippets.

View mjfrigaard's full-sized avatar
🏠
Working from home

Martin J Frigaard mjfrigaard

🏠
Working from home
View GitHub Profile
@mjfrigaard
mjfrigaard / download-youtube-data.md
Last active December 4, 2023 22:24
This gist shows how to download and wrangle YouTube meta data in R
@mjfrigaard
mjfrigaard / bs4_app.R
Created January 31, 2023 16:25
Create a bs4Dash shiny template
# Create a bs4Dash app
install.packages(c("purrr", "rstudioapi"))
library(purrr)
library(rstudioapi)
bs4_app <- function() {
bs4_app_code <- c(
"library(shiny)\nlibrary(bs4Dash)\n\nui <- bs4Dash::dashboardPage(title = '<NAME>',\n\t\theader = bs4Dash::dashboardHeader(\n\t\t\ttitle = bs4Dash::dashboardBrand(\n\t\t\ttitle = 'bs4Dash template',\n\t\t\tcolor = 'primary'\n\t\t\t\t)\n\t\t\t),\n\tsidebar = bs4Dash::dashboardSidebar(),\n\t\tbody = bs4Dash::dashboardBody(\n\t\t\tshiny::fluidRow(\n\t\t\t\tbs4Dash::sortable(\n\t\t\t\tbs4Dash::box(title = 'box 1', width = 12)\n\t\t\t)\n\t\t),\n\t\t\tshiny::fluidRow(\n\t\t\t\tbs4Dash::sortable(\n\t\t\t\tbs4Dash::box(title = 'box 2', width = 12)\n\t\t\t)\n\t\t\t)\n\t\t),\n\tcontrolbar = bs4Dash::dashboardControlbar()\n\t)\nserver <- function(input, output) {\n\t\t}\n\nshiny::shinyApp(ui = ui, server = server)\n")
purrr::map(.x = bs4_app_code, .f = rstudioapi::insertText)
}

meta_cols() function

This R function adds the current datetime (access_datetime), user (user), and system information (sysinfo) to a data.frame or tibble.

meta_cols <- function(data) {
    library(tibble)
    library(lubridate)
 data_raw &lt;- data
@mjfrigaard
mjfrigaard / 38-rolling-averages-wrangle.R
Created June 22, 2020 16:46
Wrangle covid-19 data for rolling averages
#=====================================================================#
# This is code to create: 38-rolling-averages-wrangle.R
# Authored by and feedback to: @mjfrigaard
# MIT License
# Version: 1.1
#=====================================================================#
# Download files into COVID-19/ folder from:
# https://github.com/CSSEGISandData/COVID-19
@mjfrigaard
mjfrigaard / jupyter-install-pkgs.R
Created December 15, 2019 17:21
Packages for installing R in jupyter notebooks
#=====================================================================#
# This is code to create: jupyter-install-pkgs.R
# Authored by and feedback to: @mjfrigaard
# MIT License
# Version: 1.0
#=====================================================================#
# packages ----------------------------------------------------------------
install.packages(c('rzmq','repr','IRkernel','IRdisplay'),
@mjfrigaard
mjfrigaard / 34.0-animate-norm-vars.R
Last active November 25, 2019 15:08
Animate normal distributions with different means and standard deviations.
#=====================================================================#
# This is code to create: 34.0-animate-norm-vars.R
# Authored by and feedback to: mjfrigaard@gmail.com
# MIT License
# Version: 1.0
# Share: http://bit.ly/gganimate-gif
#=====================================================================#
library(ggplot2)
library(gganimate)
@mjfrigaard
mjfrigaard / rayshader-error.md
Created October 11, 2019 20:32
error on rayshader package
#=====================================================================#
# This is code to create: rayshader error
# Authored by and feedback to: mjfrigaard
# MIT License
# Version: 1.0
#=====================================================================#


# error -------------------------------------------------------------------
@mjfrigaard
mjfrigaard / readxl_errror-2018-11-06.md
Created November 6, 2018 18:59
readxl error on iteration for importing many sheets into .csv files

Hi #rstats and #tidyverse folks!

I was hoping someone could help me with the error I am seeing when trying to get the functions from the excellent examples on readxl?

I have multiple sheets in an .xlsx file I want to read into data frames and write (a few) of them as .csv files.

Unfortunately I keep seeing this error:

Hypertension sample (code review)

Motivation

This project requires selecting a sample of patients who meet the following criteria.

  1. aged 18-85
  2. had 2 encounters between 2015-01-01 and 2017-12-31 with a hypertension ICD9 diagnosis

Issue in MySQL dump

The mysql dump used to create the RDB_database did not load all the tables from RDB_shared.

From Boris

I am not sure I understand what problem you have.

As you can see, all 17 Dana’s tables are present in the dump file: