Skip to content

Instantly share code, notes, and snippets.

View njtierney's full-sized avatar
🌴
On vacation

Nicholas Tierney njtierney

🌴
On vacation
View GitHub Profile

Just to build on https://gist.github.com/DavisVaughan/294b6934ae1f291634534ac952dcfa02, here is what we did in order to get this to work with Devel R.

We created a C file, named zzz.c in src/main/zzz.c, and also had to have the following header files in the below order. Then we also had to add a line to the (already existing) makefile, Makefile.in in src/main/Makefile.in, where we added a line zzz.c under SOURCES_C = \.

Then we did the regular debug stuff:

  1. Sys.getpid()
  2. Copy pid into LLDB debugger
  3. Add breakpoint in C code
  4. Run code to trigger breakpoints
sample.int <- function(n, size = n, replace = FALSE, prob = NULL,
prob_method = c("sequential", "marginal", "poisson"),
useHash = (n > 1e7 && !replace && is.null(prob) && size <= n/2)){
stopifnot(length(n) == 1L)
replace_or_no_prob <- is.null(prob) || replace
if (replace_or_no_prob){
size <- size %||% n
if (useHash) {
## will work with size > n/2 but may be slow.
# compare `{sampling}`, `{sondage}` on up-brewer Dev R,
# which is at: https://github.com/hturner/r-svn/tree/unequal-prob-sampling
# comparing UPbrewer method to `{sampling}` package
# And to implementation of  this in `{sondage}`:
# `sondage::sample_int(..., method = "marginal")`
# {sampling} is installed from CRAN
# {sondage} is installed from github:  https://github.com/dickoa/sondage
# from https://thredds.nci.org.au/thredds/catalog/gb6/BRAN/BRAN2020/daily/catalog.html?dataset=gb6/BRAN/BRAN2020/daily/ocean_temp_1995_06.nc
library(tidyverse)
library(terra)
nci_url <- "https://thredds.nci.org.au/thredds/fileServer/gb6/BRAN/BRAN2020/daily/ocean_temp_1995_06.nc"
vsi <- function(url) glue::glue("/vsicurl/{url}")
sf::gdal_utils("info", vsi(nci_url))
ncdf4::nc_open()
# SST data of Antarctica
co2_url <- "https://gml.noaa.gov/webdata/ccgg/trends/co2/co2_trend_gl.csv"

library(tidyverse)
co2_raw <- read_csv(co2_url,
                    skip = 24) |> 
  mutate(
    date = ISOdate(year = year, month = month, day = day),
    .before = smoothed
  )
library(terra)
#> terra 1.7.78

We are exploring an approach in {geotargets} for splitting up a raster into tiles and then using that to split up rasters that we will then do tasks on. To do this, Eric wrote this create_tile_exts function, which is powered by terra::getTileExtents:

# Set-up ---------
library(conmat)
library(tidyverse)
library(gratia)
library(patchwork)
set.seed(2022 - 12 - 19)
# Obtain data from conmat ----------
---
title: example multi figures
format: html
---
We can also see that there is an interesting relationship between Ozone and temperature.
```{r}
#| label: fig-aq
#| fig-cap:
library(tidyverse)

group <- tribble(
  ~group,           ~golding, ~senior, ~hao,  ~windecker, ~tierney,  ~stretton, ~chikolwa, ~duncan, ~ryan, ~avenell, ~shearer, ~ohiolel, ~saraswati,
   "KRIA",           TRUE,     TRUE,   TRUE,  TRUE,       TRUE,      TRUE,      TRUE,      TRUE,    TRUE,  TRUE,     TRUE,     TRUE,    TRUE,
   "CHA",            TRUE,     TRUE,   TRUE,  TRUE,       TRUE,      TRUE,      TRUE,      TRUE,    TRUE,  FALSE,     TRUE,     TRUE,    TRUE,
   "IDEM",           TRUE,     TRUE,   TRUE,  TRUE,       TRUE,      TRUE,      TRUE,      TRUE,    TRUE,  FALSE,     TRUE,     TRUE,    TRUE,
   "IDDU",           TRUE,     TRUE,   TRUE,  TRUE,       TRUE,      TRUE,      TRUE,      TRUE,    TRUE,  FALSE,     TRUE,     TRUE,    TRUE,
   "IIDM",           TRUE,    FALSE,  FALSE, FALSE,      FALSE,     FALSE,     FALSE,     FALSE,   FALSE,  FALSE,    FALSE,    FALSE,   FALSE,