This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
(defcustom company-backends `(;; Emacs Lisp | |
;; In newer versions of Emacs, company-capf is used instead. | |
,@(unless (version< "24.3.51" emacs-version) | |
(list 'company-elisp)) | |
;; BBDB https://www.emacswiki.org/emacs/CategoryBbdb | |
company-bbdb | |
;; nxml-mode | |
;; In Emacs >= 26, company-capf is used instead. | |
,@(unless (version<= "26" emacs-version) | |
(list 'company-nxml)) |
This file contains hidden or 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
(cl-loop | |
for str in (thread-last | |
(number-sequence 1 60) | |
(seq-filter (lambda (x) (zerop (% x 5)))) | |
(seq-map (lambda (x) (concat "000" (number-to-string x)))) | |
(seq-map (lambda (x) (substring x -3))) | |
(seq-map (lambda (x) (concat "raw" x)))) | |
do (dired-mark-files-regexp str)) |
This file contains hidden or 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
--- | |
title: "tableone (Lightning talk at Partners R User Group Meeting)" | |
author: "Kazuki Yoshida" | |
date: "`r format(Sys.time(), '%Y-%m-%d')`" | |
output: html_document | |
--- | |
```{r, message = FALSE, tidy = FALSE, echo = F} | |
## knitr configuration: http://yihui.name/knitr/options#chunk_options | |
library(knitr) |