Advertisement · 728 × 90

Posts by Anna Krystalli

Preview
R-Universe Named R Consortium Top-Level Project We're excited to announce R-Universe has been named the R-Consortium's newest Top-Level Project.

Excited and grateful that R-Universe is R Consortium's newest top-level project! This means sustained support for @rOpenSci.hachyderm.io.ap.brid.gy's platform for discovery and publishing of #rstats packages. Hats off to @jeroenooms.bsky.social for his leadership!

ropensci.org/blog/2024/12...

1 year ago 72 28 0 3
Screenshot of the following R code
library(dplyr)
library(aocodeR)

input <- aoc_get_input(
  day = 4, year = 2024,
  cookie_path = ".cookie.txt"
) |>
  readr::read_fwf()

n_cols <- nchar(input[1, "X1", drop = TRUE])
cols <- seq(n_cols)
colnames <- paste0("X", seq(n_cols))
tbl <- input |>
  tidyr::separate(X1, colnames, sep = cols, remove = TRUE) |>
  as.matrix()

# Part 1 ----
detect_xmas <- function(tbl, loc, dir = c(1L, 0L)) {
  idx <- data.frame(
    row = loc[1] + seq(3L) * dir[1],
    col = loc[2] + seq(3L) * dir[2]
  ) |>
    as.matrix()
  x <- try(head(tbl[idx], 3L), silent = TRUE)
  if (inherits(x, "try-error") || length(x) != 3L) {
    return(FALSE)
  }
  isTRUE(all.equal(c("X", x), c("X", "M", "A", "S")))
}

locs <- which(tbl == "X", arr.ind = TRUE)
locs <- split(locs, row(locs))

purrr::map(locs, ~ {
  loc <- .x
  dirs <- list(
    c(1, 0), c(0, 1),
    c(-1, 0), c(0, -1),
    c(1, 1), c(-1, -1),
    c(1, -1), c(-1, 1)
  )
  purrr::map_lgl(
    dirs,
    ~ detect_xmas(tbl, loc = loc, dir = .x)
  )
}) |>
  unlist() |>
  sum()

## PART 2 ----
detect_x_mas <- function(tbl, loc = loc) {
  rows <- loc[1] + c(-1, 1)
  cols <- loc[2] + c(-1, 1)

  grid <- try(
    tbl[
      seq(rows[1], rows[2]),
      seq(cols[1], cols[2])
    ],
    silent = TRUE
  )
  if (inherits(grid, "try-error") || any(dim(grid) != c(3, 3))) {
    return(FALSE)
  }
  all(
    setequal(grid[c(1, 9)], c("M", "S")),
    setequal(grid[c(3, 7)], c("M", "S"))
  )
}

locs <- which(tbl == "A", arr.ind = TRUE)
locs <- split(locs, row(locs))

purrr::map_lgl(
  locs,
  ~ detect_x_mas(tbl, loc = .x)
) |>
  sum()

Screenshot of the following R code library(dplyr) library(aocodeR) input <- aoc_get_input( day = 4, year = 2024, cookie_path = ".cookie.txt" ) |> readr::read_fwf() n_cols <- nchar(input[1, "X1", drop = TRUE]) cols <- seq(n_cols) colnames <- paste0("X", seq(n_cols)) tbl <- input |> tidyr::separate(X1, colnames, sep = cols, remove = TRUE) |> as.matrix() # Part 1 ---- detect_xmas <- function(tbl, loc, dir = c(1L, 0L)) { idx <- data.frame( row = loc[1] + seq(3L) * dir[1], col = loc[2] + seq(3L) * dir[2] ) |> as.matrix() x <- try(head(tbl[idx], 3L), silent = TRUE) if (inherits(x, "try-error") || length(x) != 3L) { return(FALSE) } isTRUE(all.equal(c("X", x), c("X", "M", "A", "S"))) } locs <- which(tbl == "X", arr.ind = TRUE) locs <- split(locs, row(locs)) purrr::map(locs, ~ { loc <- .x dirs <- list( c(1, 0), c(0, 1), c(-1, 0), c(0, -1), c(1, 1), c(-1, -1), c(1, -1), c(-1, 1) ) purrr::map_lgl( dirs, ~ detect_xmas(tbl, loc = loc, dir = .x) ) }) |> unlist() |> sum() ## PART 2 ---- detect_x_mas <- function(tbl, loc = loc) { rows <- loc[1] + c(-1, 1) cols <- loc[2] + c(-1, 1) grid <- try( tbl[ seq(rows[1], rows[2]), seq(cols[1], cols[2]) ], silent = TRUE ) if (inherits(grid, "try-error") || any(dim(grid) != c(3, 3))) { return(FALSE) } all( setequal(grid[c(1, 9)], c("M", "S")), setequal(grid[c(3, 7)], c("M", "S")) ) } locs <- which(tbl == "A", arr.ind = TRUE) locs <- split(locs, row(locs)) purrr::map_lgl( locs, ~ detect_x_mas(tbl, loc = .x) ) |> sum()

Screenshot of the following R code:
library(aocodeR)
# -- Process input ----
input <- aoc_get_input(
  day = 5, year = 2024,
  cookie_path = ".cookie.txt"
) |>
  readr::read_lines()

updates <- input[stringr::str_detect(input, ",")] |>
  strsplit(split = ",") |>
  purrr::map(~ as.integer(.x))

rules <- input[stringr::str_detect(input, "\\|")] |>
  strsplit(split = "\\|") |>
  purrr::map(~ as.integer(.x))

# PART 1 ----
## -- Functions ----
get_later_pages <- function(page, rules) {
  is_page_rule <- purrr::map_lgl(rules, ~ .x[1] == page)
  rules[is_page_rule] |>
    purrr::map_int(~ .x[2])
}
mem_get_later_pages <- memoise::memoise(get_later_pages)

check_page <- function(i, update, rules) {
  page <- update[i]
  later_pages <- mem_get_later_pages(page, rules)
  !any(update[seq(i - 1)] %in% later_pages)
}

check_update <- function(update, rules) {
  for (i in seq_along(update)[-1]) {
    if (!check_page(i, update, rules)) {
      return(FALSE)
    }
  }
  TRUE
}
get_middle <- function(x) {
  x[length(x) %/% 2 + 1]
}

## -- workflow ----
valid_updates <- purrr::map_lgl(updates, ~ check_update(.x, rules))
updates[valid_updates] |>
  purrr::map_int(get_middle) |>
  sum()

# Part 2 ----
# Functions
get_earlier_pages <- function(page, rules) {
  is_page_rule <- purrr::map_lgl(rules, ~ .x[2] == page)
  rules[is_page_rule] |>
    purrr::map_int(~ .x[1])
}
mem_get_earlier_pages <- memoise::memoise(get_earlier_pages)

reorder_update <- function(update) {
  idx <- purrr::map_int(
    seq_along(update),
    ~ page_idx(.x, update, rules)
  ) |>
    order()
  update[idx]
}
page_idx <- function(i, update, rules) {
  sum(update[-i] %in% mem_get_earlier_pages(update[i], rules)) + 1
}

# Workflow
invalid_updates <- updates[!valid_updates]
purrr::map(invalid_updates, reorder_update) |>
  purrr::map_int(get_middle) |>
  sum()

Screenshot of the following R code: library(aocodeR) # -- Process input ---- input <- aoc_get_input( day = 5, year = 2024, cookie_path = ".cookie.txt" ) |> readr::read_lines() updates <- input[stringr::str_detect(input, ",")] |> strsplit(split = ",") |> purrr::map(~ as.integer(.x)) rules <- input[stringr::str_detect(input, "\\|")] |> strsplit(split = "\\|") |> purrr::map(~ as.integer(.x)) # PART 1 ---- ## -- Functions ---- get_later_pages <- function(page, rules) { is_page_rule <- purrr::map_lgl(rules, ~ .x[1] == page) rules[is_page_rule] |> purrr::map_int(~ .x[2]) } mem_get_later_pages <- memoise::memoise(get_later_pages) check_page <- function(i, update, rules) { page <- update[i] later_pages <- mem_get_later_pages(page, rules) !any(update[seq(i - 1)] %in% later_pages) } check_update <- function(update, rules) { for (i in seq_along(update)[-1]) { if (!check_page(i, update, rules)) { return(FALSE) } } TRUE } get_middle <- function(x) { x[length(x) %/% 2 + 1] } ## -- workflow ---- valid_updates <- purrr::map_lgl(updates, ~ check_update(.x, rules)) updates[valid_updates] |> purrr::map_int(get_middle) |> sum() # Part 2 ---- # Functions get_earlier_pages <- function(page, rules) { is_page_rule <- purrr::map_lgl(rules, ~ .x[2] == page) rules[is_page_rule] |> purrr::map_int(~ .x[1]) } mem_get_earlier_pages <- memoise::memoise(get_earlier_pages) reorder_update <- function(update) { idx <- purrr::map_int( seq_along(update), ~ page_idx(.x, update, rules) ) |> order() update[idx] } page_idx <- function(i, update, rules) { sum(update[-i] %in% mem_get_earlier_pages(update[i], rules)) + 1 } # Workflow invalid_updates <- updates[!valid_updates] purrr::map(invalid_updates, reorder_update) |> purrr::map_int(get_middle) |> sum()

Managed to spend some time catching up with
#AdventOfCode
(days 4 & 5) in
#rstats
...longer than I hoped on day 5 but satisfied to finally crack it!

aocoder 📦 for importing puzzles into R can be found here: github.com/annakrystall...

1 year ago 7 0 0 0
Preview
Software sustainability of global impact models Abstract. Research software for simulating Earth processes enables the estimation of past, current, and future world states and guides policy. However, this modelling software is often developed by sc...

New paper published

E. Nyenah, P. Döll, @danielskatz.bsky.social, and @reinecke.bsky.social, "Software sustainability of global impact models," Geoscientific Model Development, v.17(23), pp. 8593–8611, 2024. doi.org/10.5194/gmd-...

1 year ago 5 3 0 2
In R, set `options(shiny.devmode = TRUE)` in your .Rprofile or call `shiny::devmode(TRUE)`. In Python, use `shiny run` with the `--dev-mode` flag.

In R, set `options(shiny.devmode = TRUE)` in your .Rprofile or call `shiny::devmode(TRUE)`. In Python, use `shiny run` with the `--dev-mode` flag.

Did you know #Shiny has a developer mode that turns on auto-reloading, an in-app error console and more? #RStats

1 year ago 50 6 3 0
Gingerbread house

Gingerbread house

My favourite Xmas tradition and recipe passed down by my American mom is making gingerbread houses!

It's sth I now do with my fiancee's niece, nephew and their cousins...we made 5 this year!! Sure it would warm mom's heart to know ♥️

1 year ago 1 0 0 0
Preview
New report highlights the scientific impact of open source software Two of the scientists who won this year’s Nobel Prize for cracking the code of proteins’ intricate structures relied, in part, on a series of computing

“We don’t value software, data, and methods in the same way we value papers, even though those resources empower millions of scientists” 💯

www.statnews.com/sponsor/2024...

1 year ago 162 73 3 7
Preview
Introducing the {messy} package | Nicola Rennie The {messy} R package takes a clean dataset, and randomly adds mess to create data more similar to that which you'd find in the real world. This is an easy way for educators to create data sets that g...

🎉 The {messy} package is now available on CRAN! 🎉

Read the introductory blog post here: nrennie.rbind.io/blog/introdu...

#RStats #StatsEd #DataScience

1 year ago 135 33 10 4
Getting started with elmer

If you're interested in trying out LLMs in #rstats but don't know where to begin, I've added a few two vignettes to elmer: elmer.tidyverse.org/articles/elm... and elmer.tidyverse.org/articles/pro...

1 year ago 265 64 10 1
Dani bay

Dani bay

After being battered by high winds for the last 3 weeks, a calm morning has finally dawned!

1 year ago 5 0 0 0
Advertisement

Same!

1 year ago 1 0 0 0
Preview
🕵️‍♂️ RegExplain – Garrick Aden-Buie An RStudio addin slash utility belt for regular expressions

Need help with regular expressions in R? Check out the RegExplain RStudio add-in by @grrrck.xyz

www.garrickadenbuie.com/project/rege...

#RStats #RegExp #RegEx #RStudio

1 year ago 90 22 5 1

😍😎

1 year ago 1 0 0 0

I'm an #rstats RSE too! And eager to connect with others on here too.

Thanks for this list BTW! It made it much easier to find folks quickly

1 year ago 4 0 1 0

I would love love love to connect to more Research Software Engineers!

This is quite #rstats heavy currently, but is open to all of any level!

go.bsky.app/4kfWypW

1 year ago 104 37 26 0