Skip to content

Instantly share code, notes, and snippets.

View muschellij2's full-sized avatar

John Muschelli muschellij2

View GitHub Profile
@muschellij2
muschellij2 / Convert_index.R
Created December 13, 2021 17:55
Scripts for 3D YouTube Video
# rm(list=ls())
convert_index <- function(infile="index_original.html", outfile = "index.html"){
trim <- function (x) gsub("^\\s+|\\s+$", "", x)
ff <- file(infile)
dat <- readLines(ff)
close(ff)
where.scene <- which(dat == " r0 = new X.renderer('r0');")
@muschellij2
muschellij2 / blah.sh
Last active June 24, 2021 20:37
blah
#!/bin/bash
echo "I ran a script" > blah.txt
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
file \
git \
libapparmor1 \
libgc1c2 \
better_fetch_pubmed_data = function (pubmed_id_list, retstart = 0, retmax = 500, format = "xml",
encoding = "UTF8")
{
myIDlist <- pubmed_id_list
if ((!is.list(myIDlist)) | is.na(myIDlist$WebEnv) | is.na(myIDlist$QueryKey) |
is.na(myIDlist$Count) | !is.integer(as.integer(retstart)) |
!is.integer(as.integer(retmax))) {
message("There is an issue with the PubMed ID list you supplied. Please, call the function again and supply the result of a <get_pubmed_ids()> call as argument. Thank you.")
return(NULL)
}
@muschellij2
muschellij2 / install_old_dependencies.R
Created April 1, 2021 18:24
Install Old Dependencies in R
old_package_version = function(repos = getOption("repos")) {
all_info = vector(mode = "list", length = length(repos))
names(all_info) = repos
for (repo in repos) {
# taken from remotes:::package_find_archives
archive <- tryCatch({
tf <- tempfile(fileext = ".gz")
on.exit(unlink(tf), add = TRUE)
remotes:::download(tf, sprintf("%s/src/contrib/Meta/archive.rds",
repo))
@muschellij2
muschellij2 / read_landXML.R
Created July 6, 2020 12:21
try reading in landXML in R
library(rvest)
library(xml2)
library(sf)
library(geojsonio)
url = "http://www.landxml.org/webapps/landxmlsamples.aspx"
url_file = paste0("http://landxml.org/schema/LandXML-2.0/",
"samples/Carlson%20Software/nunosurf.xml")
xml_file = file.path("~/Downloads", basename(url_file))
if (!file.exists(xml_file)) {
@muschellij2
muschellij2 / rmd_to_df
Created July 2, 2020 03:26
Turn an rmd to a df, extracting the knitr chunks and caches.
# remotes::install_github('muschellij2/knitr')
library(knitr)
rmd_to_df = function(file) {
x = xfun::read_utf8(file)
on.exit(knitr::knit_code$restore(), add = TRUE)
res = knitr:::split_file(x, patterns = knitr::all_patterns$md)
classes = sapply(res, attr, "class")
blocks = res[classes %in% "block"]
params = lapply(blocks, function(el) {
@muschellij2
muschellij2 / read_mat.R
Created April 21, 2020 16:00
Read MATLAB File
read_mat = function(mat) {
L = try({
R.matlab::readMat(mat)
})
if (!inherits(L, "try-error")) {
return(L)
}
names = rhdf5::h5ls(mat)$name
convert_mat_string = function(x) {
@muschellij2
muschellij2 / walk_source.R
Last active February 20, 2020 21:14 — forked from gadenbuie/walk_source.R
Walk an R source file and run each command in RStudio automatically on a delay
walk_source <- function(
file = NULL,
delay = 1.5,
clear_each_cmd = TRUE,
wait_for_press = TRUE,
style = styler::tidyverse_style,
record_screen = TRUE,
...
) {
if (record_screen) {
@muschellij2
muschellij2 / file_exists.R
Last active October 10, 2019 17:12
R function alternative for `file.exists`.
file_exists = function(...) {
x = list(...)
x = unlist(...)
x = unname(x)
df = data.frame(x = x,
bn = basename(x),
dn = dirname(x),
index = 1:length(x),
stringsAsFactors = FALSE)
dn = unique(df$dn)
@muschellij2
muschellij2 / bet2.cpp
Last active September 27, 2019 19:46
bet2 with self-intersection threshold as argument.
/* BET - Brain Extraction Tool
BETv1 Steve Smith
BETv2 Mickael Pechaud, Mark Jenkinson, Steve Smith
FMRIB Image Analysis Group
Copyright (C) 1999-2006 University of Oxford */
/* Part of FSL - FMRIB's Software Library