@coolbutuseless@fosstodon.org
@coolbutuseless@fosstodon.org avatar

coolbutuseless

@coolbutuseless@fosstodon.org

Nerd.

This profile is from a federated server and may be incomplete. Browse more on the original instance.

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

Introducing {callme} - a package for easily(?) compiling and loading C code into

I use this idea when testing small snippets of C code as part of developing bigger ideas & packages.

Using this approach, it is also possible to quickly link to other C libraries. In the example below, I link to the 'zstd' library and request the library version number as a string.

This is a nice(?) wrapper around "R CMD COMPILE/SHLIB"

https://github.com/coolbutuseless/callme

Example The following example compiles a code snippet into a C library and then executes the function from R using SCall() . The function name in C is add_ , which means that this is the first argument to .call() i.e. .Call(*add_", wee) The function name could be almost any valid C function name, but I prefer to use an underscore suffix to indicate that this a C function meant to be called from R. library(callme) code <- " SEXP add_(SEXP vall_, SEXP val2_) { return ScalarReal(asReal(vall_) + asReal(val2_)); } callme(code) .Call("add_", 1, 2.5) n
Linking against an installed library The following code snippet asks for the version of the zstd library which is (already) installed on the computer, and return it as a character string. We need to tell R when compiling the code: to look in the /opt/homebrew/include directory for zstd.h . « to look for the actual zstd library in /opt/homebrew/lib . « tolink to the zstd library ( -lzstd ) code < r( "zstd.h" SEXP version_() { return mkString(ZSTD_versionString()); ¥ ) callme(code, cpp_flags = "-I/opt/homebrew/include”, ld_flags = “-L/opt/homebrew/lib -lzstd") .Call("version_")
[> library(callme) R PRSI W + + + SEXP add_(SEXP vall_, SEXP valz)) { + return ScalarReal(asReal(vall ) + asReal(val2_)); L] o > callme(code) clang -arch armé4 -I"/Library/Frameworks/R. framework/Resources/include” -DNDEBUG -I/opt/R/arm64/i nclude -fPIC -falign-functions=64 -Wall -g -02 -c callme-16da937995196.c -0 callme-16da9379951 9.0 using C compiler: ‘Apple clang version 14.0.3 (clang-1403.0.22.14.1)° using SDK: ‘MacOSX13.3.sdk’ clang -arch armé4 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_mo dule -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/1ib -L/opt/R/arm64/lib -0 callme-16da937995196.50 callme-16da937995196.0 ~F/Library/Frameworks/R. framework/. . -framework R -WL,-framework -WL,CoreFoundation > .Call("add_", 1, 2.5) 1] 3.5 > ](https://cdn.fosstodon.org/media_attachments/files/110/740/491/318/612/573/original/4cdd4a5cd3c9fe83.png)

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

Introducing {rbytecode} - an assembler/disassembler for R's bytecode.

Modern R ultimately runs most(?) code in a stack based virtual machine.

This package allows you to disassemble and assemble R bytecode to understand what is happening right at the core of R execution.

Github: https://github.com/coolbutuseless/rbytecode

Note: This package is also a book which goes into more details & is a reference for R bytecode instruction set.

The book is available for free on leanpub: https://leanpub.com/rbytecode

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar
coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

Eye-watering stats on packages with unit tests on CRAN

60+% of packages had no tests

From data in 2017 by @juliasilge : https://juliasilge.com/blog/mining-cran-description/

#RStats

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

Word of the day: fidanglydoodads

@josiah

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

Work-in-progress: New JSON library

Early results on a microbenchmark look promising!

Fastest JSON parser for R?

Note: Benchmark is not be indicative of real-world use cases. Performance gap narrows on larger examples.

Output of code benchmarking new JSON parser. Results show new parser is faster than jsonlite and RcppSimdJson on this microbenchmark.

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

Adventures in updating legacy code.

Found this gem of a variable name today:

fit_Rand_Data

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

Introducing {yyjsonr} a new, fast JSON package - Fastest(?) JSON parser for R?

  • ~2x to 10x faster than {jsonlite}
  • supports both read and write
  • ndjson support (evolving)

If you're in the market for fast JSON and have particular requirements get in touch! (file a GH issue, toot me, etc)

See github & pkg docs for benchmarks and usage.

https://github.com/coolbutuseless/yyjsonr

https://coolbutuseless.github.io/package/yyjsonr/index.html

Screenshot of benchmarking code and graph showing yyjsonr package speed compared to other packages for converting R to JSON. The yyjsonr package is fastest.

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

Update {yyjsonr} v0.1.1

Fastest(?) JSON/NDJSON parser for

  • Removed overhead when setting config options - now much faster for small JSON strings
  • Added from_json_raw() to parse json from raw bytes containing utf-8 chars

Benchmarks galore on github README.

  • 10x faster than jsonlite parsing 'iris' dataset from file.
  • 10x faster than jsonlite parsing 1000 rows of ndjson from file

Feedback welcomed as I figure out a roadmap to CRAN

https://github.com/coolbutuseless/yyjsonr

https://coolbutuseless.github.io/package/yyjsonr/index.html

Benchmark of yyjsonr package reading ndjson from file. yyjsonr shows speed advantage over other json packages for R

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

Recently I learned (by RTFMing) that all(?) tests in {testthat} support a 'label' argument to produce more verbose error messages.

I've found this handy when I have lots of test inputs and reference results stored in a named lists:

for (nm in names(test)) {
expect_equal(test[[nm]], ref[[nm]], label = nm)
}

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

{yyjsonr} Update v0.1.7. Fast read/write of JSON/GeoJSON/NDJSON.

I did a great renaming of the user-facing functions.

It's not perfect, but it's better than it was before (see image).

https://github.com/coolbutuseless/yyjsonr

Table showing comparison of features across R JSON packages.
Image showing speed comparison of R JSON packages.

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

Developer note: Nearly every single one of my projects has started with these 3 thoughts:

  1. That'd be cool.
  2. It can't be that hard.
  3. It should only take me a few hours to do.

Then I spend the next month* riding the Dunning Kruger wave - realising there's so much I don't know that I don't know! - and thinking my past self a fool for ever thinking this was possible.

...

It is nice when they occasionally pan out...

(*) year

coolbutuseless, (edited ) to random
@coolbutuseless@fosstodon.org avatar

Introducing {moggy} - a package for creating markdown documents from scratch without using a template.

My use-case for this package is to create markdown documentation directly from meta-information stored in lists/data.frames

The development progress of this package is proportional to the quality of the image of the cat in the logo.

https://github.com/coolbutuseless/moggy

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

I ❤️ {rhub} !

Just checked new package on 9 R setups - including valgrind and address sanitizer.

Such a confidence builder that the package won't barf too much on CRAN :)

gaborcsardi, to random
@gaborcsardi@fosstodon.org avatar

R 4.4.0 is coming in less than one month!

With rig you can try the first alpha easily while keeping your current R version. Run

rig add next

to install, and then

R-next

to start R 4.4.0 alpha.

On Windows, macOS or one of the many supported Linux distributions.

See https://github.com/r-lib/rig#readme

coolbutuseless,
@coolbutuseless@fosstodon.org avatar

{rig} is brilliant! In half-an-hour I:

  • Installed rig for the first time on macOS
  • Installed R 4.2 and 4.4
  • Used the handy shortcuts to start my project in Rstudio with these alternate R versions
  • Tested my new package locally to see some version-specific options worked

@gaborcsardi

coolbutuseless, to ELI5
@coolbutuseless@fosstodon.org avatar

WTF is going on at @Posit ?

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

This was a lot of work to get this new graphics device package to this point.

Yet it looks like I've done nothing at all :)

animation of layers of a simple ggplot in R

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

Now that this pkg is actually in a state where it can do something useful, I can quickly realize some ideas for rendering. From idea to proof-of-concept render was ~15 minutes.

This is a ggplot object rendered into isometric layers.

It's just a shear + foreshortening transformation applied to the geometry, with points further offset in the y axis.

#RStats

#RStats

Isometric transformed ggplot with layer separation.

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

I am paying close attention to the R-devel discussion on R API definition.

A package I'm working on (rmonocypher) uses connections to enable encryption in lots of useful places in R for seamless/easy data encryption.

But connection registration in R code is "non API", meaning that you can't write a new connection in a package!

The connection API has been stable for 10 years. Not sure why its use is verboten.

#RStats

https://github.com/coolbutuseless/rmonocypher

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

Programming tip: When writing extensions for R using C:

  • Allocate memory before trying to copy data into it.
  • Copying into a NULL pointer is bad.

Like and subscribe for more "great" programming tips!!!

#RStats

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

{emphatic} now renders to latex!

Which means that Quart/Rmd rendering to PDF now works!

https://github.com/coolbutuseless/emphatic

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

{emphatic} typst support: added!

Good news: It works!

Bad news: I can't work out how to disable text wrapping and/or set overflow in a block to be hidden.

Large tables make 'typst' want to reflow the text which I expressly do NOT want to do.

I've added a 'font_size' option to help deal with this, but being able to control reflow/overflow would be better!

https://github.com/coolbutuseless/emphatic

#RStats

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

hive: has anyone resubmitted a package to CRAN and been asked to fix their use of SET_TRUELENGTH?

coolbutuseless, to demoscene
@coolbutuseless@fosstodon.org avatar

#RStats users, if your method for creating tables isn't letting you create retro demo effects then what even is the point?

This is {emphatic} output to an SVG animation played back in the browser with 'scale_colour_gradient2()' and some sine waves doing the effect.

#RStats #DemoScene

video/mp4

coolbutuseless, to random
@coolbutuseless@fosstodon.org avatar

{rmonocypher} is now feature complete! Simple (yet bulletproof) encryption

Core encryption function is

encrypt(mtcars, filename = "secure.rds", key = "my secret key!")

Security/usability feedback welcomed!

Below the surface there's lots going on!

  • Argon2 key derivation
  • RFC8439 "Authenticated Encryption with Additional Data" using ChaCha20 stream cipher + Poly1305 Message Authentication
  • Required random bytes (nonce) sourced from OS CSPRNG

https://github.com/coolbutuseless/rmonocypher
#RStats

  • All
  • Subscribed
  • Moderated
  • Favorites
  • megavids
  • cubers
  • DreamBathrooms
  • tacticalgear
  • magazineikmin
  • mdbf
  • Youngstown
  • everett
  • slotface
  • ngwrru68w68
  • rosin
  • thenastyranch
  • kavyap
  • khanakhh
  • JUstTest
  • tester
  • InstantRegret
  • cisconetworking
  • Durango
  • ethstaker
  • osvaldo12
  • GTA5RPClips
  • modclub
  • Leos
  • provamag3
  • normalnudes
  • anitta
  • lostlight
  • All magazines