Skip to content

Instantly share code, notes, and snippets.

View cgpu's full-sized avatar
:octocat:

Christina Chatzipantsiou cgpu

:octocat:
View GitHub Profile
@cgpu
cgpu / soft_coded_Dropbox_dir.Rmd
Last active September 19, 2018 05:24
ExecutionPC-agnostic Dropbox directory path.
# Find os:
```{r}
os <- Sys.info()[[1]]
```
# Create OS-relevant Dropbox file path:
```{r}
if(os == "Windows"){
@cgpu
cgpu / dataframe_2_csv_2_dataframe.R
Last active December 7, 2020 20:07
Snippet for foolproof writing of dataframes into .csv files in R
# Preview dataframe to write beforehands:
head(my_fav_df)
# Check dimensions of the dataframe you wish to write in a .csv file:
dim(my_fav_df)
# Set path of (i)output directory (ii) filename:
savedir = "home/cgpu/favorite_dir/"
FILE = paste0(savedir, 'favorite_filename', '.csv')
# 3 relevant packages:
## Basic,
```{r}
utils::sessionInfo()
```
## Slightly cooler, nicer output display
## DWNL: https://github.com/r-lib/sessioninfo
```{r}
@cgpu
cgpu / slice_df_on_column_values.R
Last active May 11, 2019 13:26
Select rows from a dataframe based on a list of values contained in column of choice.
names_to_keep <- c('item1', 'item2', 'etc')
df_sliced <- df[is.element(df$name , names_to_keep ), ]
@cgpu
cgpu / PAC_analysis_pipeline.py
Created September 4, 2018 05:48
Analysis pipeline for filtering of SNPs. Not DRY or fast. For archiving purposes and future revisit.
#!/usr/bin/env python3
# TO RUN JUST TYPE:
# python3 snp_selection.py
# INPUT FILES AND OPTIONS WILL BE REQUESTED AS USER INPUT
# THE FOLLOWING PROGRAMME IS PART OF the PACtool package (https://pypi.python.org/pypi/PACtool)
# Highlighting errors, warnings, messages
Color code what R tells you when you need to knw something about your code.
This cool snippet found here: https://selbydavid.com/2017/06/18/rmarkdown-alerts/<br>
Kuddos to [David](https://twitter.com/TeaStats) for sharing!
```{r echo=FALSE}
# Cool snippet for color coding errors
knitr::knit_hooks$set(
@cgpu
cgpu / rmd_2_word_document_format.Rmd
Last active September 11, 2018 11:47
Convert from rmarkdown to word document
# https://rmarkdown.rstudio.com/word_document_format
```
---
title: "From rmd to word document"
date: "`r Sys.Date()`"
output:
word_document:
toc : TRUE #to include a table of contents in the output
toc_depth : 3 # Depth of headers to include in table of contents
@cgpu
cgpu / install_pandoc_with_installr_R_pckg.R
Created September 5, 2018 12:49
Install pandoc for cool-looking rmd outputs.
# installing/loading the package:
if(!require(installr)) { install.packages("installr"); require(installr)} #load / install+load installr
# Installing pandoc
install.pandoc()
@cgpu
cgpu / rmd_2_word_document_arguments.Rmd
Last active September 5, 2018 12:52
Header for knitting an rmd to word_document with arguments to tune.
---
title: 'My very favorite title'
date: "`r Sys.Date()`"
output:
word_document:
toc : TRUE #to include a table of contents in the output
toc_depth : 3 # Depth of headers to include in table of contents
fig_width : # Default width (in inches) for figures
fig_height : # Default width (in inches) for figures
fig_caption : TRUE #to render figures with captions
@cgpu
cgpu / init_df_of_know_dim_soft_coded_colnames.R
Last active January 3, 2019 13:23
Initialize dataframe with NA
# Dataframe with the aliquot IDs of the cohort's samples, 96 x 4
aliquot_ID <- data.frame(matrix(NA, nrow = length(ofsthelse), ncol = length(LCMS_id)))
colnames(aliquot_ID) <- LCMS_id