Skip to content

Instantly share code, notes, and snippets.

View coolbutuseless's full-sized avatar

mikefc coolbutuseless

View GitHub Profile
@coolbutuseless
coolbutuseless / email.txt
Last active April 26, 2024 23:58
A proposed email to R-devel on connections
Subject: Clarificaiton requested on 'connections' interface.
Hi All,
I am confused on the status of being able to create custom connections in R.
The functions 'R_new_custom_connection()' and 'R_GetConnection()'
(defined in 'R_ext/Connections.h') are marked in 'sotools.c' as 'nonAPI'.
This would seem to indicate that it is not for use in packages as it will
@coolbutuseless
coolbutuseless / simplebenchmark-yyjsonr.R
Created January 17, 2024 21:43
rcppsimdjson simplebenchmark including yyjsonr
file <- system.file("jsonexamples", "twitter.json", package="RcppSimdJson")
jsontxt <- readLines(file)
res <- microbenchmark::microbenchmark(jsonify = jsonify::validate_json(jsontxt),
jsonlite = jsonlite::validate(jsontxt),
simdjson = RcppSimdJson::validateJSON(file),
ndjson = ndjson::validate(file),
RJSONIO = RJSONIO::isValidJSON(file),
yyjsonr = yyjsonr::validate_json_file(file),
@coolbutuseless
coolbutuseless / hey_rstats.R
Last active June 20, 2023 16:29
run dplyr commands verbally
library(carelesswhisper)
library(styler)
library(dplyr)
library(stringr)
ctx <- whisper_init()
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#' Record audio and convert to text
@coolbutuseless
coolbutuseless / wasm.Rmd
Created July 29, 2022 11:39
Toy WASM interpreter in R
---
title: "Toy WASM interpreter in base R"
author: "mikefc"
date: 2022-07-29T18:05:00+10:00
categories: ['Rstats']
tags: ["R"]
---
```{r, include = FALSE}
knitr::opts_chunk$set(
@coolbutuseless
coolbutuseless / pong.R
Created July 24, 2022 00:57 — forked from Enchufa2/pong.R
Pong in R
# remotes::install_github("coolbutuseless/eventloop")
Pong <- R6::R6Class(
"pong",
public = list(
initialize = function(width=10, height=7, speed=0.02) {
require(grid)
private$width <- width
private$height <- height
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Use x11() device as Rstudio device has "issues" with grid.locator()
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
library(grid)
x11(type = 'cairo')
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Some linear-ish points in range/domain [0,1]
@coolbutuseless
coolbutuseless / reactive.Rmd
Created May 5, 2022 21:09
Reactive objects with eventloop
---
title: "Reactive Objects"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Reactive Objects}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# ##### ### # #####
# # # # # # # # #
# # # # # # # #
# ##### # # # # #####
# # # # ####### # #
# # # # # # #
# ####### ### # #####
@coolbutuseless
coolbutuseless / mutate.listframe
Created April 19, 2021 09:47 — forked from MyKo101/mutate.listframe
Application of the mutate method to a listframe
listframe <- function(...){
structure(
tibble(...),
class = c("listframe","tbl_df","tbl","data.frame")
)
}
lf <- listframe(
a = list(1,c("a","b","c"),matrix(1:4,2,2)),
@coolbutuseless
coolbutuseless / ray-tracer.Rmd
Last active July 22, 2021 11:48
Simple ray tracer in Base R
MIT Licensed. Copyright (c) 2021 mikefc@coolbutuseless.com
Share and Enjoy.
## Introduction
This code was a personal challenge to write a simple ray-tracer in pure R.
Ray tracing is an example of something which is really silly to do in base R,
and I'd be interested to see how others would approach this problem.