Anna Krystalli's Avatar

Anna Krystalli

@annakrystalli

R-RSE: Research Software Engineering Services in R Working remotely from the beautiful island of Syros, Greece https://www.r-rse.eu/

554
Followers
441
Following
6
Posts
21.11.2024
Joined
Posts Following

Latest posts by Anna Krystalli @annakrystalli

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...

03.12.2024 16:42 πŸ‘ 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...

05.12.2024 20:49 πŸ‘ 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-...

05.12.2024 14:06 πŸ‘ 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

05.12.2024 18:08 πŸ‘ 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 β™₯️

05.12.2024 08:16 πŸ‘ 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...

04.12.2024 00:08 πŸ‘ 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

04.12.2024 09:17 πŸ‘ 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...

29.11.2024 15:45 πŸ‘ 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!

27.11.2024 07:39 πŸ‘ 5 πŸ” 0 πŸ’¬ 0 πŸ“Œ 0

Same!

22.11.2024 11:47 πŸ‘ 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

20.11.2024 20:06 πŸ‘ 90 πŸ” 22 πŸ’¬ 5 πŸ“Œ 1

😍😎

21.11.2024 16:46 πŸ‘ 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

21.11.2024 16:42 πŸ‘ 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

20.11.2024 12:44 πŸ‘ 104 πŸ” 37 πŸ’¬ 26 πŸ“Œ 0