This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### tableone export helpers | |
### Turn tableone output matrix into tidyverse data_frame | |
tableone_mat_to_data_frame <- function(mat) { | |
mat %>% | |
as.data.frame() %>% | |
tibble::rownames_to_column(var = "Variable") %>% | |
tibble::as_data_frame() | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Swap dimension specification | |
(defun my-reverse-org-table-dimension (size) | |
(let* ((split (org-split-string size " *x *")) | |
(pos1 (nth 1 split)) | |
(pos0 (car split))) | |
(concat pos1 "x" pos0))) | |
;; Wrapper to fix the dimension | |
(defun org-table-create-reverse-table-dimension (old-fun &optional size) | |
"Query for a size and insert a table skeleton. | |
SIZE is a string Rows x Columns like for example \"2x3\". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; Issue reported by Brian | |
;; An ipython code snippet does not execute upon C-c C-c in org-mode. | |
;; "Evaluation of this ipython code block is disabled." is encountered. | |
;;; ob-core.el | |
;; This is the function showing the error message. | |
(defun org-babel-check-evaluate (info) | |
"Check if code block INFO should be evaluated. | |
Do not query the user, but do display an informative message if | |
evaluation is blocked. Returns non-nil if evaluation is not blocked." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#+BEGIN_SRC R :session *R* :results output :exports both | |
suppressPackageStartupMessages(library(tidyverse)) | |
data1 <- read_tsv("./data.tsv") | |
print(data1, | |
width = Inf) | |
library(jsonlite) | |
jsonlite::toJSON(data1, pretty = TRUE) | |
#+END_SRC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Write multiple data_frames to a single xlsx file (use openxlsx) | |
write_lst_of_df_to_xlsx <- function(lst_df, file, font_size) { | |
## Create a workbook object with one sheet | |
## https://rdrr.io/cran/openxlsx/man/setColWidths.html | |
wb <- createWorkbook() | |
## Work on each data_frame | |
for (i in seq_along(lst_df)) { | |
sheet_name <- ifelse(is.null(names(lst_df[i])), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Taken from http://www.significantdigits.org/2017/10/switching-from-base-r-to-tidyverse/ | |
| Base R command | Tidyverse Command | Comment | | |
|-----------------------------------+--------------------------------------------+---------------------------------------------------------------| | |
| read.csv() | read_csv() | also see read_delim(), read_tsv() and readxl::read_xlsx() | | |
| sort(), order() | arrange() | see also order_by() | | |
| mtcars$mpg = ... | mutate() | see also transmute() which drops existing variables | | |
| mtcars[,c(“mpg”, “am”)], subset() | select(), rename() | see also pull() | | |
| mtcars[mtcars$am == 1,], subset() | filter() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Turn tableone output matrix into tidyverse data_frame | |
tableone_mat_to_data_frame <- function(mat) { | |
bind_cols(data_frame(Variable = rownames(mat)), | |
as_data_frame(mat)) | |
} | |
### Write a xlsx file | |
write_tableone_mat_to_xlsx <- function(tableone_mat, file) { | |
## Create a workbook object with one sheet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Jpeg < Formula | |
desc "Image manipulation library" | |
homepage "http://www.ijg.org" | |
url "http://www.ijg.org/files/jpegsrc.v8d.tar.gz" | |
sha256 "00029b1473f0f0ea72fbca3230e8cb25797fbb27e58ae2e46bb8bf5a806fe0b3" | |
bottle do | |
cellar :any | |
rebuild 2 | |
sha256 "85d1f6055de99c1b764c697498bb86d003f5d24b324133f036f0393b97b3e869" => :sierra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Implement multivariate version of Rubin's formula | |
## eq 14 in https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4029775/ | |
## Page 97 of https://www.amazon.com/Multiple-Imputation-Nonresponse-Surveys-Donald/dp/0471655740 | |
AlternativeMIcombine.default <- function (results, variances, call = sys.call(), df.complete = Inf, ...) { | |
m <- length(results) | |
oldcall <- attr(results, "call") | |
if (missing(variances)) { | |
variances <- suppressWarnings(lapply(results, vcov)) | |
results <- lapply(results, coef) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun org-babel-get-all-src-block-info () | |
"Get information on all src blocks in an org file." | |
(interactive) | |
(let ((lst '())) | |
(save-excursion | |
;; Go to the beginning of buffer | |
(beginning-of-buffer) | |
(while (condition-case err | |
;; Try to move to the next src block. | |
(org-next-block nil nil org-babel-src-block-regexp) |