Commit 2ab5a283 authored by Holger Brandl's avatar Holger Brandl

removed concat

parent 2fbf46c3
...@@ -166,14 +166,12 @@ replaceNA <- function(x, withValue) { x[is.na(x)] <- withValue; x } ...@@ -166,14 +166,12 @@ replaceNA <- function(x, withValue) { x[is.na(x)] <- withValue; x }
## related: http://cran.r-project.org/web/packages/R.cache/R.cache.pdf ## related: http://cran.r-project.org/web/packages/R.cache/R.cache.pdf
cache_it <- function(expr, cacheName){ cache_it <- function(expr, cacheName=paste0("cache_", substr(digest(expr), 1,6))){
cacheFile <- paste0(".", cacheName, ".RData") cacheFile <- paste0(".", cacheName, ".RData")
if(file.exists(cacheFile)){ if(file.exists(cacheFile)){
# print("using cache")
local(get(load(cacheFile))) local(get(load(cacheFile)))
} else { } else {
# print("evaluating expression")
result <- eval(expr) result <- eval(expr)
save(result, file=cacheFile) save(result, file=cacheFile)
result result
...@@ -182,7 +180,8 @@ cache_it <- function(expr, cacheName){ ...@@ -182,7 +180,8 @@ cache_it <- function(expr, cacheName){
## Examples ## Examples
#mydata <- quote(iris %>% filter(Species=="setosa")) %>% cache_it("tt") #mydata <- quote(iris %>% filter(Species=="setosa")) %>% cache_it("tt")
#mydata <- quote( { print("evaluation expr"); iris %>% filter(Species=="setosa") } ) %>% cache_it("tt") #mydata <- quote(iris %>% filter(Species=="setosa")) %>% cache_it()
#mydata <- quote( { print("evaluate expr"); iris %>% filter(Species=="setosa") } ) %>% cache_it()
######################################################################################################################## ########################################################################################################################
#### File System #### File System
......
require.auto(ggplot2) require.auto(ggplot2)
require.auto(scales) require.auto(scales)
require(grid) require.auto(grid)
scale_fill_redgreed <- function() scale_fill_manual(values = c("red","darkgreen")) scale_fill_redgreed <- function() scale_fill_manual(values = c("red","darkgreen"))
...@@ -10,7 +9,6 @@ rotXlab <- function() theme(axis.text.x = element_text(angle = 90, hjust = 1)) ...@@ -10,7 +9,6 @@ rotXlab <- function() theme(axis.text.x = element_text(angle = 90, hjust = 1))
# Multiple plot function # Multiple plot function
# #
# ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects) # ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects)
...@@ -85,12 +83,12 @@ ggsave2 <- function(gplot=last_plot(), width=8, height=6, prefix="", saveData=FA ...@@ -85,12 +83,12 @@ ggsave2 <- function(gplot=last_plot(), width=8, height=6, prefix="", saveData=FA
} }
fileBaseName <- ifelse(nchar(prefix)>0, concat(prefix, " - ", title), title) fileBaseName <- ifelse(nchar(prefix)>0, paste0(prefix, " - ", title), title)
## clean up weired characters ## clean up weired characters
fileBaseName <- str_replace_all(fileBaseName, "[$%/?]", "_") fileBaseName <- str_replace_all(fileBaseName, "[$%/?]", "_")
fileName = concat(fileBaseName, concat(".", outputFormat)) fileName = paste0(fileBaseName, paste0(".", outputFormat))
## remove line-breaks and trim spaces ## remove line-breaks and trim spaces
fileName = str_replace_all(str_replace_all(fileName, "\\n", ""), "[ ]{2,}", " ") fileName = str_replace_all(str_replace_all(fileName, "\\n", ""), "[ ]{2,}", " ")
...@@ -98,7 +96,7 @@ ggsave2 <- function(gplot=last_plot(), width=8, height=6, prefix="", saveData=FA ...@@ -98,7 +96,7 @@ ggsave2 <- function(gplot=last_plot(), width=8, height=6, prefix="", saveData=FA
ggsave(fileName, width=width, height=height, ...) ggsave(fileName, width=width, height=height, ...)
if(saveData){ if(saveData){
write.delim(gplot$data, file= concat(fileBaseName, ".txt")) write.delim(gplot$data, file= paste0(fileBaseName, ".txt"))
} }
return(fileName) return(fileName)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment