Skip to content

Instantly share code, notes, and snippets.

View jcheng5's full-sized avatar

Joe Cheng jcheng5

View GitHub Profile
@jcheng5
jcheng5 / image_dimensions.R
Last active April 18, 2020 18:09
Determine file image size in R
jpeg_dimensions <- function(filename, bytes = 1024) {
bytes <- readBin(filename, "raw", n = bytes)
if (length(bytes) < 2 || bytes[[1]] != 0xFF || bytes[[2]] != 0xD8) {
stop("Couldn't decode jpeg")
}
ff <- which(bytes == 0xFF)
c0 <- which(bytes == 0xC0)
```{js echo=FALSE}
function enshadowGtTable(tableEl) {
var containerEl = tableEl.parentElement;
var styleEl = containerEl.previousElementSibling;
if (containerEl.tagName !== "DIV" || styleEl.tagName !== "STYLE") {
throw new Error("Unexpected document structure");
}
var shadowDiv = document.createElement("div");
shadowDiv.classList.add("gt-shadow-container");
containerEl.parentElement.insertBefore(shadowDiv, styleEl);
@jcheng5
jcheng5 / README.md
Last active March 10, 2021 16:02
Installing R-devel on Solaris 10 VM

As far as CRAN is concerned, there are two flavors of R on Solaris: one that is built using the Solaris Studio compiler, and one that is built using the GNU/gcc toolchain. The latter is far more up-to-date, but if your package requires it, then your DESCRIPTION file must declare that with the line SystemRequirements: GNU make.

These instructions are for configuring, building, and installing R-devel using the GNU/gcc toolchain (only).

You'll need VMWare Fusion on Mac, or VMWare Workstation (?) on Windows/Linux.

Get Solaris VM

Download the Solaris VM provided by Jeroen Ooms: https://github.com/jeroen/solarisvm

@jcheng5
jcheng5 / gist:34ef026bdefd3c9b558920b9a9804c01
Last active July 25, 2019 09:44
Solaris 10 R-devel csw
590 pkgutil -i wget
603 pkgutil -i gcc5gfortran
609 pkgutil -i -y libiconv_dev
613 pkgutil -i -y zlib_dev
615 pkgutil -i -y libz_dev
620 pkgutil -i -y liblzma_dev
622 pkgutil -i -y libpcre_dev
624 pkgutil -i -y libcurl_dev
634 pkgutil -i -y libcurl4_dev
647 pkgutil -y -i gmake
@jcheng5
jcheng5 / app.R
Created July 5, 2019 15:35
Celsius <=> Fahrenheit
library(shiny)
ui <- fluidPage(
numericInput("temp_c", "Celsius", NA),
numericInput("temp_f", "Fahrenheit", NA)
)
server <- function(input, output, session) {
c_to_f <- function(c, decimals = 1) {
round((c * 9 / 5) + 32, decimals)
# BE SURE TO set your Mapbox access token with:
# options(mapbox.accessToken = "...")
library(htmltools)
library(leaflet)
mapboxgl_deps <- list(
htmlDependency(
"mapbox-gl-js", "0.53.0", c(href = "https://api.mapbox.com/mapbox-gl-js/v0.53.0/"),
script = "mapbox-gl.js",
num_suffix <- function(x, base = 1000, suffixes = c("K", "M", "B", "T")) {
if (length(suffixes) == 0) {
tibble(
scale_by = rep_len(1, length(x)),
suffix = rep_len("", length(x))
)
}
i <- floor(log(abs(x), base = base))
@jcheng5
jcheng5 / addDynamicTiles.R
Created January 19, 2019 16:38
Leaflet dynamic tiles
library(shiny)
library(leaflet)
#' Add a tile layer whose source is an R function
#'
#' @param tileFunc A function(x, y, z) that returns a 256x256 image object
#' suitable for passing to `png::writePNG`.
#' @seealso [leaflet::addTiles()] for other parameters
addDynamicTiles <- function(map, tileFunc,
layerId = paste0("leafletRaster", sample.int(9999999, 1)),
@jcheng5
jcheng5 / 1-original.R
Created November 9, 2018 16:32
Simple Shiny app, with and without plot caching
library(ggplot2)
library(shiny)
ui <- fluidPage(
varSelectInput("color_by", "Color by:", diamonds, selected = "cut"),
plotOutput("plot")
)
server <- function(input, output, session) {
output$plot <- renderPlot({
@jcheng5
jcheng5 / .bashrc
Created October 31, 2018 17:46
Launch Shiny apps from command line
# Examples:
# shiny # Launch the Shiny app in the current directory
# shiny path/to/app # Launch the Shiny app at the specified path
# shiny . launch.browser=F,port=8000 # Launch Shiny in the current dir with given options
function shiny {
R --vanilla -q -e "shiny::runApp(\"${1:-.}\", launch.browser=TRUE, $2)"
}