Skip to content

Instantly share code, notes, and snippets.

View yjunechoe's full-sized avatar
🐣

June Choe yjunechoe

🐣
View GitHub Profile
library(lintr)
test_file <- tempfile(fileext = ".txt")
cat(
"
1 + 1
switch('x', a = (1 + 1), b = 10, 12) # this is fine
x <- 20
switch('x', b = 20, a = 12) # should find this one
print('foo')
@benzipperer
benzipperer / function_names.R
Created October 19, 2024 01:42
show all the function names in a given set of R scripts using the treesitter package
# show all the function names in a given set of R scripts
function_definitions = function(files) {
purrr:::map(files, function_definitions_script) |>
purrr::list_rbind()
}
function_definitions_script = function(file) {
text = brio::read_lines(file) |>
paste(collapse = "\n")

List files and stream (non-spatial) table from within a tarball on CRAN.

(we need dev gdalraster for the full dir/vsitar listing capability, but reading from remote files or archives is available in many GDAL versions and existing supported GDAL packages on CRAN)

cransrc <- "https://cran.r-project.org/src/contrib" 
library(gdalraster)  ## for listing dirs recursively we need gh:USDAForestService/gdalraster for now
#> GDAL 3.10.0dev-449d5f09b7, released 2024/08/26, GEOS 3.12.2, PROJ 9.4.1

## list all R packages .tar.gz