Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

[Discussion]: Handling operations that use/modify RNG

Offen
#291 2 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
25/100
Issue-Typ
Feature
Klarheit
Muss geklärt werden
Aktivitätsstatus
Aktiv
Tech-Stack
r
Bereich
backend

Rechercherichtung

Beginnen Sie mit den Codepfaden within und teal.code::eval_code und verfolgen Sie dann, wie get_code(names = ...) und der Code-Parser partiellen Code erstellen. Lesen Sie Issue 278 und die verknüpften RNG-Referenzen, um Seed-Tracking und Reproduzierbarkeit zu verstehen. Als erledigt gilt die Aufgabe, wenn sich die Beitragenden auf eine reproduzierbare Richtlinie für Zufallsoperationen bei der Ausführung partiellen Codes einigen und diese implementieren.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

core discussion
What is your question?

Per discussion with @llrs-roche, here are some topics for the contributors to discuss and research.

Problem

Random/stoichastic operations are not being well handled in within/teal.code::eval_code, in particular when code parse is being used.

In the section below you can observe that q |> get_code(names = "IRIS") is not fully reproducible as the random operations before were not included, nor was the RNG state updated before code execution

Reproducible code

This code highlights the 2 main problems:

  1. set.seed() and other random operations are not kept in partial code (q |> get_code(names = "XXX"))
  2. MTCARS/IRIS random operations are influenced by preceding code
library(teal.code)
q <- qenv() |> 
  within({
    IRIS <- datasets::iris
    MTCARS <- datasets::mtcars
    set.seed(1)
    .random <- runif(1)
    IRIS$new <- runif(nrow(IRIS))
    MTCARS$new <- runif(nrow(MTCARS))
  })

q |> get_code() |> cat()
#> iris <- datasets::iris
#> mtcars <- datasets::mtcars
#> set.seed(1)
#> .random <- runif(1)
#> iris$new <- runif(nrow(iris))
#> mtcars$new <- runif(nrow(mtcars))

q |> get_code(names = "IRIS") |> cat()
#> IRIS <- datasets::iris
#> IRIS$new <- runif(nrow(IRIS))

local({
  eval(str2expression(q |> get_code(names = "IRIS")))
  q$IRIS |> rlang::hash() |> cat("# hash qenv IRIS\n")
  IRIS |> rlang::hash() |> cat("# hash reproduced IRIS\n")
})
#> 9bba33c8ed5cd90cd13316f35f812f55 # hash qenv IRIS
#> c90a89c1814206bc19fdc32d04d1eefa # hash reproduced IRIS

q |> get_code(names = "MTCARS") |> cat()
#> MTCARS <- datasets::mtcars
#> MTCARS$new <- runif(nrow(MTCARS))

local({
  eval(str2expression(q |> get_code(names = "MTCARS")))
  q$mtcars |> rlang::hash() |> cat("# hash qenv MTCARS\n")
  mtcars |> rlang::hash() |> cat("# hash reproduced MTCARS\n")
})
#> 2c0a8a99dc147d5445c3b49d035665b2 # hash qenv MTCARS
#> 6755d143ff87b73a1196c186cec7e86a # hash reproduced MTCARS
Reference material
Possible set of solutions
  • Use teal.code::eval_code() and # @linksto XXXXX to include random operations
    • Status quo
    • Cons: Requires character base code execution and requires manual maintenance
  • Detect random seed at start and inform user
  • Track random seed and incorporate it in code execution
  • When using code parser, re-run partial code to sync modules with reproducible code (while keeping set.seed() expressions)
    • cons: slow down teal app even more and data is not consistent with initial data argument in teal.
  • Always include set.seed() expression and hope it doesn't have a big impact
Code of Conduct
  • I agree to follow this project's Code of Conduct.
Contribution Guidelines
  • I agree to follow this project's Contribution Guidelines.
Security Policy
  • I agree to follow this project's Security Policy.
Vorherrschende Sprache
R
Sterne
12
Forks
11
Ø Merge
8 T. 15 Std.
Gemergte PRs (30 T.)
2

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus insightsengineering/teal.code

Alle Issues in insightsengineering/teal.code

Ähnliche Issues

Weitere Issues zu R

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.