Skip to content

Instantly share code, notes, and snippets.

View rmflight's full-sized avatar

Robert M Flight rmflight

View GitHub Profile
    if (!requireNamespace("piececor")) remotes::install_github('brshallo/piececor')

    ## Loading required namespace: piececor

    library(dplyr)

    set.seed(1234)
    x <- seq(.01, 3*pi, pi/100)
    y <- sin(x) + rnorm(length(x), sd = 0.25)
m = matrix(rnorm(100), 10)
rownames(m) = paste0("row", 1:10)
colnames(m) = paste0("column", 1:10)
ht = draw(Heatmap(m, name = "mat"))
highlight_row = function(which, padding = unit(1, "mm"), gp = gpar()) {
row_order = row_order(ht)
i = which(row_order == which)
nr = length(row_order)
@rmflight
rmflight / example_dendrogram.md
Created April 7, 2021 20:43
trying to add labels to a dendrogram
library(ggraph)
#> Loading required package: ggplot2
library(igraph)
#> 
#> Attaching package: 'igraph'
#> The following objects are masked from 'package:stats':
#> 
#>     decompose, spectrum
#> The following object is masked from 'package:base':
@rmflight
rmflight / test_duplicated.md
Created November 17, 2020 01:13
testing duplicated
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
@rmflight
rmflight / p.adjust.R
Last active June 27, 2020 00:59
changes to p.adjust
# File src/library/stats/R/p.adjust.R
# Part of the R package, https://www.R-project.org
#
# Copyright (C) 1995-2018 The R Core Team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
@rmflight
rmflight / warnings_errors.md
Last active January 15, 2020 15:01
Common messages and errors in R, and what they mean

Notice!

This gist is no longer going to be updated. Instead, check out the page at https://rmflight.github.io/rerrors/, or the GitHub project itself at https://rmflight.github.io/rerrors/

Installing packages

You don't need to do 'install.packages("tidyverse")' every time. Install is installing it on your system. You only need to do it again if you re-install R, or want a newer version. 'library()' loads it for use, and 'install.packages()' installs it to your computer.

Error in instal.packages("tidyverse") : could not find function "instal.packages

@rmflight
rmflight / install_tinytex.sh
Last active October 31, 2019 19:42
installing tinytex system wide instead of just user.
# borrowed from the Rocker setup at
# https://github.com/rocker-org/rocker-versioned/blob/3d62b38a1310/verse/Dockerfile#L50-L52
wget -qO- "https://github.com/yihui/tinytex/raw/master/tools/install-unx.sh" | sh -s - --admin --no-path
sudo mv ~/.TinyTeX /opt/TinyTeX
sudo /opt/TinyTeX/bin/*/tlmgr path add
sudo tlmgr install metafont mfware inconsolata tex ae parskip listings
sudo tlmgr path add
Rscript -e "source('https://install-github.me/yihui/tinytex'); tinytex::r_texmf()"
sudo chown -R root:staff /opt/TinyTeX
sudo chmod -R g+w /opt/TinyTeX
@rmflight
rmflight / smaller_latex_table.R
Created October 31, 2019 14:02
creates a smaller table
smaller_latex_table = function(kable_table, size = "tiny"){
split_table = strsplit(kable_table, "\n", )[[1]]
centering_loc = grepl("centering", split_table)
top_table = split_table[seq(1, which(centering_loc))]
bottom_table = split_table[seq(which(centering_loc)+1, length(split_table))]
new_table = c(top_table,
paste0("\\", size),
bottom_table)
structure(new_table, format = "latex", class = "knitr_kable")
}
@rmflight
rmflight / lid_status.sh
Created August 12, 2019 20:29
checking lid status
# check status of lid for wakeup
# su
# echo "LID0" > /proc/acpi/wakeup
alias lid_status="cat /proc/acpi/wakeup | grep LID0"
lid_status
@rmflight
rmflight / raw_method.R
Last active June 11, 2019 18:19
method extraction from raw thermo files
# Copyright Robert M Flight, 2019
# MIT Licensed. Use at your own risk, with no warranty.
#' extract raw method
#'
#' Given a Thermo ".raw" file, attempts to extract the "method"
#' definition from a translated hexdump of the file.
#'
#' @param in_file The Thermo raw file to extract
#' @param output_type string, data.frame or json
#'