Created
February 9, 2015 09:03
-
-
Save vzemlys/751887b31657649a6a5c to your computer and use it in GitHub Desktop.
Save Rstudio history database into a nicer format
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
library(dplyr) | |
library(magrittr) | |
library(lubridate) | |
library(bit64) | |
library(stringr) | |
lns <- readLines("~/.rstudio-desktop/history_database") %>% str_split(pattern=":",n=2) | |
hist_db <- data_frame(epoch=as.integer64(sapply(lns,"[[",1)),history=sapply(lns,"[[",2)) | |
hist_db %<>% mutate(nice_date = as.POSIXct(epoch/1000,origin = "1970-01-01",tz = "EET")) | |
hist_db %<>% mutate(day = ceiling_date(nice_date,unit = "day")-days(1)) | |
hist_db %<>% select(-epoch) | |
dd <- hist_db$day %>% unique %>% sort | |
ff <- "~/R/hist_nice.txt" | |
cat("R history","\n",rep("-",80),"\n",file=ff,sep="") | |
for(i in 1:length(dd)) { | |
cat("\n\n",format(dd[i]),"\n",rep("-",80),"\n",file=ff,sep="",append=TRUE) | |
hist_db %>% filter(day==dd[i]) %>% select(nice_date,history) %>% arrange(nice_date) %>% | |
write.table(ff,sep="\t", quote=F, row.names=FALSE, col.names=FALSE, append=TRUE) | |
} |
This script assumes that the rstudio history file lives in a specified place and has the following structure:
TimeStamp:history_line
If you get this error either the file is not there or the history file is corrupted.
Thanks a lot!
It's useful!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Vaidas,
maybe you have any clue why I get an error: