forked from chunjie-sam-liu/leng1r
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcjFun.R
38 lines (32 loc) · 1.02 KB
/
cjFun.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#' Clear working session
#'
#' Function to transform P-values into symbols of significance (***)
#' @param s A vector of P-values
#' @return TRUE for clear
#'
#' @author C.J.
#' @export
clearSession <- function(){
lapply(paste('package:',names(sessionInfo()$otherPkgs),sep=""),detach,character.only=TRUE,unload=TRUE)
}
#' Write table
#'
#' Function to write.table with regular parameter
#' @param data Data.frame to be written
#' @param path Directory to write
#' @return NULL
#'
#' @author C.J.
#' @export
write.tsv<-function(x = "", file = ""){
write.table(x, file = file, append = F, quote = F, sep = "\t", eol = "\n", na = "NA", dec = ".", row.names = F, col.names = T, qmethod = 'escape')
}
#' Convert signif numeric to math symbol annotation
#' @param signif numeric vector
#' @return expression object vector
numeric_2_plotmath <- function(x){
require(tidyverse)
require(latex2exp)
str_split(format(signif(x, 3)), "e[\\+\\-]") %>%
sapply(function(x){TeX(paste('$',x[1],' \\times 10^{',x[2],"}$", sep = ""))})
}