Skip to content

Instantly share code, notes, and snippets.

View xhdong-umd's full-sized avatar

xianghui dong xhdong-umd

View GitHub Profile
@xhdong-umd
xhdong-umd / model_selection.html
Last active July 28, 2017 16:29
model selection test result
This file has been truncated, but you can view the full file.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
@xhdong-umd
xhdong-umd / test_parallel.Rmd
Last active July 14, 2017 23:33
test parallel
---
title: "test parallel"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
if (!require("pacman")) install.packages("pacman")
pacman::p_load(ctmm, data.table, parallel)
data("buffalo")
@xhdong-umd
xhdong-umd / 1. intro.md
Last active May 26, 2017 15:38
R function that decompress zip, gz, bzip2, xz into temp file, run function then remove temp file

The need of this came from the fact that read.csv can read zip files directly but data.table::fread cannot take connections as input since it requires random file seek. There is simple usage of data.table::fread(paste0("zcat < ", PATH_TO_FILE)) but that depend on command line tool gzip, which is not always available in windows. See here for more details.

The code is based on R.utils::decompressFile with lots of modifications:

  1. no more removing input file. I lost several data files and puzzled too much time because of this even if I read the document and knew this behavior in the beginning.
  2. According to ?connections, `gzfile`` can handle gz, bzip2, xz. No need to specify and use different functions for uncompress.
  3. The only exception is gzfile cannot handle zip. We can use unzip to decompress file directly without need of connections. unzip does not support Unicode filenames as introduced in zip 3.0. See more in ?unzip for its li