Skip to content

Instantly share code, notes, and snippets.

View muschellij2's full-sized avatar

John Muschelli muschellij2

View GitHub Profile
@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 / run_matlab.R
Created August 15, 2014 15:19
Matlab code needed for running in R
#' @title Find matlab path
#'
#' @description This tries to find matlab's path using a system which
#' command, and then, if not found, looks at \code{getOption("matlab.path")}. If not path is found, it fails.
#' @export
#' @return Character of command for matlab
get_matlab = function(){
find.matlab <- system("which matlab", ignore.stdout=TRUE)
matcmd <- 'matlab -nodesktop -nosplash -nodisplay -r '
if (find.matlab != 0){
@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 / travis_helpers.sh
Last active November 4, 2020 19:24
Travis Helpers
#!/bin/bash
# https://gist.github.com/muschellij2/64f9104ccec09deb85d4928071b3c9e8
# set -e
# Comment out this line for quieter output:
# set -x
export cran_set='options(repos = "http://cran.rstudio.com"); '
# we may be able to change to remotes
export ig_package=devtools
@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) {