Skip to content

Instantly share code, notes, and snippets.

View njtierney's full-sized avatar
🐝
Back at work

Nicholas Tierney njtierney

🐝
Back at work
View GitHub Profile
==> Testing R file using 'testthat'

ℹ Loading greta
ℹ Initialising python and checking dependencies, this may take a moment.

✔ Initialising python and checking dependencies ... done!

TensorShape conversions remain stable

... Offending code

x <- shape(NA, 3)
tensorflow::as_tensor(x)
# using distributional
options(tidyverse.quiet = TRUE)
library(tidyverse)
library(distributional)

dat_dist <- tibble(
  means = c(1:5),
  sds = c(5:1),
  vals = means + rnorm(5, 0.1, 0.1),
pct_resupply <- tibble::tribble(
~Section, ~Days, ~`Distance.(mi)`, ~`Total.(mi)`, ~Resupply,
"Campo to Mt. Laguna", 3L, 42.9, 42.9, "B",
"Mt. Laguna to Warner Springs", 4L, 66.6, 109.5, "B",
"Warner Springs to Idyllwild", 5L, 69.9, 179.4, "B",
"Idyllwild to Big Bear City", 6L, 95.6, 275, "B",
"Big Bear City to Wrightwood", 6L, 94.5, 369.5, "B",
"Wrightwood to Agua Dulce", 6L, 85, 454.5, "B",
"Agua Dulce to Tehachapi or Mojave", 6L, 112, 566.5, "B",
"Tehachapi to Kennedy Meadows", 8L, 135.5, 702.2, "M",
clean_site_name_forbes <- function(site_name, out_name){
dplyr::case_when(
str_detect(site_name, "ST") ~ "STP Forbes",
str_detect(site_name, "Muddy") ~ "STP Forbes",
str_detect("ST", site_name) ~ "STP Forbes",
.default = "unmatched"
)
}
n.pixel <- 1000
n.other.spec <- 20
spec.names <- letters[1:(n.other.spec+1)]

## Geographic covariates affecting species abundance
x <- matrix(rnorm(2*n.pixel),nrow=n.pixel)

## Geographic covariate causing selection bias (correlated with x1)
z <- scale(x[,1] + rnorm(n.pixel)*sqrt(.95^(-2)-1))
library(polite)
library(tidyverse)
library(httr2)
library(rvest)
url <- "https://njt.micro.blog/2023/08/19/pct-day-kennedy.html"
extract_pct_summary <- function(url){
raw <- bow(url) %>% scrape()
raw %>%
library(tidyverse)

# 4 data sets
# survey
n <- 100
create_survey <- function(n, year, id = 1:n){
  tibble(
  id = id,
  year = year,
library(tidyverse)
# 4 data sets
# survey
n <- 100
create_survey <- function(n, year, id = 1:n){
tibble(
id = id,
year = year,
province = sample(1:9, size = n, replace = TRUE),
library(tidyverse)
cause_for_dismissal <- c("A",
                         "B",
                         "C")

vic_moz_long <- tibble(
  id = 1:5,
  species = c("B", "C", "D", "E", "F")
)