Skip to content

Instantly share code, notes, and snippets.

View mhpob's full-sized avatar

Mike O'Brien mhpob

View GitHub Profile
@mhpob
mhpob / caveplot.R
Last active March 17, 2022 20:35
"Cave plot" proof of concept
library(dplyr)
df_north <- tibble(
week = 1:53,
N = sample(0:15, 53, replace = T)
)
df_south <- tibble(
week = 1:53,
@mhpob
mhpob / mgcv_random_effects.R
Last active August 24, 2023 18:00
Random effects specifications
## This was originally used in review, where Year was nested within Blocks
library(mgcv)
# In the BodyWeight data, Rat is nested in Diet with no repeated Rats across Diets
# Analogous to Year nested in Blocks with no repeated Years across Blocks
data('BodyWeight')
# Dummy code levels of Diet as for YearBlock in manuscript
BodyWeight$Diet1 <- ifelse(BodyWeight$Diet == 1, 0, 1)
@mhpob
mhpob / reilly-field
Created April 19, 2021 14:05
Check JRA field conditions with Powershell
[xml]$Content = Invoke-WebRequest -Uri "https://water.weather.gov/ahps2/hydrograph_to_xml.php?gage=rmdv2&output=xml"
$smry = $content.site.forecast.datum.primary."#text" | measure -Minimum
if($smry.minimum -lt 5.5){
New-BurntToastNotification -Text "Get ready to go sampling!" ,
"Richmond-Westham is forecast to be <5.5 ft."
}
@mhpob
mhpob / loop_chunks.md
Last active April 19, 2021 14:05
Programmatically create RMarkdown chunks

The following was adapted from the blog post here.

The key is to use results = "asis". More information can be found here. Basically:

  • anything output with cat() will be evaluated as RMarkdown.
  • anything output with print() will be evaluated with R.
for(i in seq(min(station_key$year), max(station_key$year), 1)){
  
@mhpob
mhpob / mgcv_errs.md
Last active January 13, 2022 19:35
mgcv errors and description on how to fix

mgcv

gam

Error in gam.reparam(UrS, sp, grderiv) : NA/NaN/Inf in foreign function call (arg

You're likely trying to take the log of zero.

bam(~s(, bs = 'so'))

# Create track
set.seed(8675309)
turning_angles <- runif(100, 0, 2*pi)
runs <- runif(100, 0, 50)
fake_track <- data.frame(x = 0,
y = 0,
t = 1)
@mhpob
mhpob / prune-local
Last active April 19, 2021 14:06
Delete and prune local branches that no longer exist.
git branch -d branch-to-delete
git fetch -p