- download old
.tar.gzfrom the package archive - run
R CMD INSTALL .tar.gzor to get the dependencies installed runinstall.packages(".tar.gz", repos = NULL, type = "source")
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
| # batch renames files with hyphens to underscores | |
| for i in `ls *-*` | |
| do | |
| NEW=`echo $i|tr '-' '_'` | |
| git mv $i $NEW | |
| done | |
| # or do sed on the filename with multiple options | |
| for i in `ls *.sql` | |
| do |
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
| # run three times a day (between 9am and 4pm), Mon - Fri | |
| H H(9-16)/3 * * 1-5 |
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
| -- pg dump of a specific schema from metrics db on index | |
| pg_dump metrics -h 10.1.24.39 -p 5433 -U cdt_user -n <schema_name> > <out>.sql | |
| -- select a random percentage of rows of table | |
| select * from my_table tablesample bernoulli(<percentage in numbers, e.g. 10>) | |
| -- or to select random rows in query | |
| select * from query order by random() limit 100 | |
| -- useful aggregate functions to use with GROUP BY | |
| string_agg(<field>, ';') /* equivalent to R's paste(<field>, collapse = ";") */ |
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
| # open up current file (useful for opening markdowns in chrome) | |
| :!open % | |
| # search across folder tree for test | |
| # From within buffer at top most level of folder tree to search | |
| :grep '<searchstring>' **/*.<fileending to search> or grep -R <searchstring> . to recursievely search all files in project | |
| :copen to open the quickfix list, and :ccl to close it | |
| :cn to go to the next on the quickfix list | |
| :cp to go to the previous | |
| # OR |
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
| # rename repository | |
| # change name on remote repo, copy ssh url from the clone button on main page | |
| mv <old folder> <new folder> | |
| git remote set-url origin git@github.com:genomicsengland/<new repo name> | |
| # compare local copy of file to remote | |
| git fetch origin | |
| git diff origin/master -- <path to file> | |
| # list all branches |
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
| #-- convert pdf into single page png images with p01 numbering | |
| for file in *.pdf; do | |
| echo 'converting $file' | |
| convert -density 400 -colorspace sRGB $file -scene 1 -alpha off ${file%.pdf}_p%02d.png; | |
| done |
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
| -- on query | |
| pg_dump -h 10.1.24.39 -p 5433 --schema <schema-name> <db_name> > ~/scratch/<dump_file>.sql | |
| -- local | |
| cd ~/scratch | |
| scp sthompson@10.1.24.38:~/scratch/<dump_file>.sql . | |
| sed -i .bak 's/OWNER TO cdt_user;/OWNER TO simon;/g' <dump_file>.sql | |
| psql -d <target_db> -h localhost -p 5432 -U simon < <dump_file>.sql |
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
| #-- get latest rds file from filelisting with datestamps | |
| get_latest_rds <- function(d, kw){ | |
| ls <- list.files(d, pattern = "*.rds", full.names = T) | |
| f <- sort(ls[grepl(kw, ls)], decreasing = T)[1] | |
| d <- readRDS(f) | |
| cat(paste("Fetched", f, "--", nrow(d), "rows", ncol(d), "columns\n")) | |
| return(d) | |
| } |
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
| #-- convert df to tibble | |
| tbl <- tbl_df(df) | |
| #-- aggregate by multiple groups | |
| d <- df %>% filter(<filter_conditional>) %>% | |
| group_by(<grouping_variable1>, ...) %>% | |
| summarise(<out_var> = <out_var_function_call>,...) | |
| #-- get crosstabs table and replace low counts | |
| tab_ldp <- d %>% |