r/rstats

▲ 14 r/rstats

I wish R has decorators

Like the title suggested, I want something like decorators in R where you can place the function at the top of the function you just called. I know you can do fn <- nested_fn(function(...) {} but it feels like slightly verbose.

Edit: To be clear, I am aware with function factories, but I wish it has proper syntactic sugar to sympathize that you modify the behavior of the function, for example.

reddit.com
u/Confident_Bee8187 — 6 days ago
▲ 32 r/rstats+2 crossposts

ais: a plain-text index in C99, no dependencies, nothing allocated on the record path

I wrote a small tool for myself. You file a path, a link or a note under keys you choose, and get it back by those keys. What I would like comment on is how it is written, not what it does.

I came to C alongside FORTRAN, Ada 83 and Pascal in the 90s, so I think in functions, data locality and streams before objects. The rule is that memory is bounded by the structs, not by the data. Records go through one at a time, on the stack, in fixed buffers. get, find, set, merge and compact allocate nothing at all, so a 10 GB store and a 10 KB store run in the same footprint. Set operations are k-way merges over sorted posting lists: keep the head of each list and advance.

Six heap sites in 18k lines, each written down with what bounds it.

Two things I know are wrong: main() is 630 lines and the HTTP handler is 520. Both are flat dispatchers, both are too long, and both are written down as debts rather than defended.

On a million records, 85 MB store, one core: building the whole index is 7.9 s in one streaming pass, a full scan is 1.8 s (cat class), and a get on the hottest key, 270k ids, is 2.2 s. That last one used to take hours, because finding a record by id meant scanning the store; an id-to-offset index fixed it. Bulk import is still O(n^(2)) and I say so in the same doc.

C99, GPLv2+, no dependencies, plain Makefile. About 5k lines of tests, run under AddressSanitizer and UBSan on every push.

Style doc: https://github.com/Anode1/ais/blob/main/doc/dev/STYLE.md
Numbers, reproducible with a seeded generator: https://github.com/Anode1/ais/blob/main/doc/performance.txt
Code: https://github.com/Anode1/ais

u/Anode1_dev — 8 days ago
▲ 0 r/rstats

Is 1:3 R:R actually better, or are we just optimizing the wrong variable?

I’ve been testing different R:R structures and I’m starting to question the obsession with fixed 1:2 / 1:3 targets.

A 1:3 setup only needs a 25% win rate to break even mathematically before costs.

But pushing the target further can also create longer losing streaks and lower hit rates.

So I’m wondering:

Would you rather have:

A) 40% WR with 1:3 R:R
B) 55% WR with 1:1.8 R:R
C) 65% WR with 1:1.2 R:R

Assuming similar execution costs and drawdown.

I’m less interested in what sounds best and more interested in what people have actually observed live.

reddit.com
u/Curious-Spread-4197 — 7 days ago
▲ 10 r/rstats

ndexr.io is now and will forever be open source going forward

Not that I will abandon the project, not at all. Instead, I want to share so that we can all build the best software we can, together. This is the encapsulation of everything I know about R in a zip file, my workflows, everything - and I hope it helps you in your journey with shiny, R, and scientific compute as the apocalypse nears.

At the moment, it is primarily a shiny app which helps manage shiny modules in novel ways useful for working with agents as well as software distribution.

I also realize ndexr is a bioc package, with that when I get the time instead of ndexr as the “index of all my r knowledge” at some point I’ll swap it all out for rxedn.com because they had the name first and I was too lazy to change.

Hope all is well, I welcome friends and video chats if you’re ever up to talk compute, R and shiny.

u/fdren — 11 days ago
▲ 11 r/rstats

Anyone use mlr3? I have a fairly basic question about train/test partition

Essentially, I am looking at a data set with many individuals. Each individual has a number of observation dates associated with them (sometimes one date, sometimes multiple dates), and each observation date is a "data point". I want to separate the train/test data by the individuals, but keep the observation dates as "data points".

Here's a hypothetical version:

I have 30 individuals and 50 readings. Each individual has 1, 2 or 3 readings. I want to do a train/test split so I have 20 individuals in the train and 10 in the test. I don't care as much how many readings I have in each set, but the default method would be to partition the 50 readings without regard to the individuals.

Is there a way I can do that with this package?

reddit.com
u/affnn — 10 days ago
▲ 2 r/rstats

Help!! Can't locate dataset

I'm sorry if this is a stupid question but I'm desperate.

I just cannot load a certain dataset from a specific package. I've tried removing and reinstalling the package and restarting the IDE to no avail.

Idk if it matters but I'm using R 4.6.1, the package is "mlbench" and the dataset is "PimaIndiansDiabetes2".

Thank you in advance!!

reddit.com
u/Funky-Mango1468 — 11 days ago
▲ 7 r/rstats

HELP! duckdb and callr causing Invalid Error: IO Error on Macos

Whats up guys?!

I have been using R and the package geocodebr , and the package uses functions of duckdband callr. I'm using macOS Tahoe (new user)

This code used to work a few time ago, but now I need to use it, and its not working.

The code:

 df_chunk <- geocodebr::geocode(
        enderecos = chunk,
        campos_endereco = campos,
        resultado_completo = FALSE,
        resolver_empates = TRUE,
        resultado_sf = FALSE,
        verboso = FALSE
    )


duckdb is storing downloaded extensions and secrets under ~/.duckdb:
ℹ /Users/USUARIO/.duckdb

This persists across sessions and is shared with the DuckDB CLI and other clients.

ℹ Run duckdb(shared_home = FALSE) to use a temporary directory instead.

ℹ See ?duckdb_storage for details and alternatives.
Error:
! ! in callr subprocess.
Caused by error in `duckdb_result(connection = conn, stmt_lst = stmt_lst, arrow = arrow)`:
! Invalid Error: IO Error: Failed to create directory "/var/folders/nx/w74wjbfs4sz5c9k_9456gw2h0000gn/T//Rtmp7gZjsr/duckdb/temp": No such file or directory
ℹ Context: rapi_execute
ℹ Error type: INVALID

Hide Traceback

Fix

Explain
    ▆
 1. └─geocodebr::geocode(...) at scripts/1_4_unifying_data.R:109:5
 2.   └─callr::r(...)
 3.     └─callr:::get_result(output = out, options)
 4.       └─throw(callr_remote_error(remerr, output), parent = fix_msg(remerr[[3]]))

I already tried to use duckdb(shared_home = FALSE) , tried to create a folder and direct the tempfile on my rprofile, tried to set on renvironment.

I dont know to solve it. Thanks a lot!

reddit.com
u/troyandabedtalkshow — 14 days ago