Skip to content

Instantly share code, notes, and snippets.

@remlapmot
remlapmot / rstan-windows-config.R
Created April 1, 2021 09:55
rstan Windows configuration
dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) dir.create(dotR)
M <- file.path(dotR, "Makevars.win")
if (!file.exists(M)) file.create(M)
cat("\n CXX14FLAGS += -mtune=native -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2",
file = M, sep = "\n", append = FALSE)
@remlapmot
remlapmot / update
Last active December 15, 2022 20:20
Update packages on a Debian based Linux distro, e.g. Ubuntu, using apt
#!/bin/bash
# update Ubuntu packages as root
sudo apt-get update && sudo apt-get --with-new-pkgs upgrade -y
# Ensure /usr/lib/R/site-library is writeable
sudo chmod 777 -R /usr/lib/R/site-library
# Update R packages as root
sudo R -q -e "update.packages(ask = FALSE)"
@remlapmot
remlapmot / r-minor-version-update-packages.R
Created May 18, 2021 20:13
Install packages from previous minor version of R into new minor version of R
# Copy packages from previous minor version of R to new version of R library directory
# from https://community.rstudio.com/t/reinstalling-packages-on-new-version-of-r/7670/3
lib_loc <- "C:\\Users\\tom\\Documents\\R\\win-library\\4.0"
to_install <- unname(installed.packages(lib.loc = lib_loc)[, "Package"])
to_install
install.packages(pkgs = to_install)
@remlapmot
remlapmot / TwoSampleMR-linux-debian-dependencies
Last active August 5, 2022 11:12
CRAN dependencies for TwoSampleMR R package to install the binary packages on Ubuntu instead of compiling from source
#!/bin/bash
sudo apt-get update -y &&
apt-get --with-new-pkgs upgrade -y &&
apt-get install -y gfortran \
libgmp-dev \
r-cran-ggplot2 \
r-cran-gridextra \
r-cran-cowplot \
r-cran-plyr \
r-cran-reshape2 \
@remlapmot
remlapmot / useful-stata-packages.do
Created September 13, 2021 13:15
Useful Stata packages
ssc install xbrcspline
ssc install metan
ssc install metareg
@remlapmot
remlapmot / useful-devtools-macos.sh
Last active February 10, 2022 15:46
Useful developer tools on macOS
# macOS developer tools without installing XCode
xcode-select --install
# homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install checkbashisms
@remlapmot
remlapmot / r-cmd-check-as-cran.R
Last active May 4, 2025 14:22
Run devtools::check() as CRAN
# Run check as CRAN (well sort of)
devtools::check(env_vars = c(NOT_CRAN = FALSE))
devtools::check(env_vars = c(NOT_CRAN = FALSE), cran = TRUE, force_suggests = TRUE, incoming = TRUE)
# Additionally not building/re-running the vignettes
devtools::check(
env_vars = c(NOT_CRAN = FALSE),
args = c(
'--no-manual',
@remlapmot
remlapmot / fix-hanging-rstudio-server.sh
Created September 21, 2021 13:27
Fix RStudio server hanging on opening
#!/usr/bin/env bash
rm -r ~/.local/share/rstudio/sessions/active
@remlapmot
remlapmot / Makevars.win
Last active February 10, 2022 15:45
Environment variables for building some R packages from source on WIndows; location ${HOME}/.R
# CC="C:\Program Files\LLVM\bin\clang.exe"
# CXX="C:\Program Files\LLVM\bin\clang++.exe"
# CXX11="C:\Program Files\LLVM\bin\clang++.exe"
# CXX14="C:\Program Files\LLVM\bin\clang++.exe"
# CXXFLAGS=-O1 -g -fsanitize=address -fno-omit-frame-pointer
# PKG_CXXFLAGS=-Og -fsanitize=address
# LDFLAGS=-fsanitize=address
## CXX14FLAGS += -mtune=native -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2
CXX14FLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function
@remlapmot
remlapmot / shrink-docker-wsl.ps1
Last active October 12, 2021 10:01
Shrink WSL2 virtual disks and Docker images
# ensure hyper v installed
# DISM /Online /Enable-Feature /All /FeatureName:Microsoft-Hyper-V
# https://www.hanselman.com/blog/shrink-your-wsl2-virtual-disks-and-docker-images-and-reclaim-disk-space
cd $env:LOCALAPPDATA\Docker\wsl\data
optimize-vhd -Path .\ext4.vhdx -Mode full
# optional
# start docker
Start-Process -FilePath "C:\Program Files\Docker\Docker\Docker Desktop.exe"