[R] How to install R package from a private git repo in Dockerfile
What if you see a great R package, but it is in a private git repo; moreover, you need to build a docker image and install the package into it? The main challenge is how can you provide the git credentials to the package installer in Dockerfile. I did Google search and found this post, in which a Personal Access Token (PAT) is passed into docker building process via an argument.
2024-11-02   schedule 1 min 53 s  
[R] Set temporary folder for R in Rstudio server
In another post, I described how to install Rstudio server on Ubuntu. In this post, I will describe how to set temporary folders for R sessions connected to an Rstudio server. This is important, because the default temporary folder /tmp could get overload easily when multiple R sessions are connected and/or big data are stored, yielding lack of space issue. Temporary folder in R One can get the temporary directory set for the current R session by typing the following command in R terminal:
2024-07-26   schedule 1 min 27 s  
[Linux] How to clone a private git repo in Dockerfile
Sometimes, one may want to download code from a private repo when building a docker image based on a Dockerfile. However, the process building the docker image doesn’t have the same privilege as the host running docker build. Fortunately, the newer version docker has provided the capability for us to pass git secrets to the image-building process. Let’s see how. Step 1: add an ssh key to github account Follow this post to generate and add ssh key to your github account, and this github account should contain the private repo to access from Dockerfile.
2024-03-03   schedule 1 min 19 s  
[Tips] Replace SAM header in a bam file
Sometimes one need to replace the SAM header lines in a bam file in order to change the order of chromosomes in the sorted bam file. Note the output of samtools sort is determined by the order of chromosomes in the SAM header (i.e., @SQ lines), so if in the header, chr1 appears after chr2, then after sorting, all the reads aligned to chr1 will appear after those aligned to chr2.
2024-03-03   schedule 1 min 54 s  
[Rmarkdown] Automate word document generation using Rmarkdown
I knew that Rmarkdown was very power to generate all kinds of document formats such as html, pdf, word, powerpoint, etc, but until recently, I have never used it to generate word documents (most time, I generated html and pdf files). When I started to generate word documents using Rmarkdown, I found that it was not so straightforward. The main issue is how to specify the different text styles to different texts, such as “Heading 1”, “Body Text”, etc.
2024-01-28   schedule 2 min 25 s  
[R] tidy evaluation in ggplot2 (part 2)
knitr::opts_chunk$set(echo=T, fig.align = "center", fig.width = 6, fig.height = 5, dpi=150, warning=FALSE) library(knitr) library(ggplot2) How to use variables to refer columns in ggplot2 Let’s start an example of making a scatter plot by using the dataset mtcars. head(mtcars) ## mpg cyl disp hp drat wt qsec vs am gear carb ## Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4 ## Mazda RX4 Wag 21.0 6 160 110 3.
2023-11-11   schedule 2 min 54 s  
[R] tidy evaluation in ggplot2
Since ggplot2 version 3.0.0, it started to support tidy evaluation, and use the technique to replace aes_ and aes_string(). In this post, I would like to show how the syntax of ggplot2 changes accordingly. knitr::opts_chunk$set(echo=T, fig.align = "center", fig.width = 6, fig.height = 5, dpi=150, warning=FALSE) library(knitr) library(ggplot2) Let’s start with an example of making a scatter plot with the dataset mtcars. library(ggplot2) plt<-ggplot(mtcars, aes(x=wt, y=mpg, color=factor(cyl))) + theme_bw() plt<-plt+geom_point() plt But what if we create a function to make the plot and accept different variables for the color aesthetics?
2023-10-23   schedule 1 min 35 s  
[R] How to overlay points over boxplots
library(ggplot2) ggplot2 is a powerful tool to visualize data. Today I would like to show how to make a boxplot and then overlay points. A pure boxplot First, let’s make a boxplot. We will use the data set ToothGrowth coming with R. dat<-ToothGrowth dat$dose<-as.factor(dat$dose) # convert the dose to a factor plt<-ggplot(dat, aes(x=dose, y=len, fill=supp)) + theme_bw() plt<-plt + geom_boxplot() plt add points with geom_jitter() Now let’s add points over the boxplots with the function geom_jitter().
2023-08-26   schedule 1 min 49 s  
[Tip] Set up RSS feed in blogdown and add it to R-bloggers
Hugo website comes with a default RSS template, which controls the format of the RSS feed for all pages in a website. One can check the RSS output by typing the following URL in the web browser: https://my-website.com/index.xml The default output seems containing a full content for the ‘’ field, but when checking a section/sub-website, the content in ‘’ seems trucated. For example, checking the following URL: https://my-website.
2023-07-21   schedule 2 min 21 s  
[Tutorial] Github/gitlab ssh key setup
One can connect to gitlab or github via ssh and https. Today, I will explain how to generate ssh key, add it to the github/gitlab account, and connect to github/gitlab using ssh in Ubuntu. Since github and gitlab are similar, I will use github as example here: Generate ssh key 1 ssh-keygen -f ~/.ssh/id_rsa_github The above command will generate two files: id_rsa_github and id_rsa_github.pub. The latter is the public key and should be copied to the github account.
2023-07-01   schedule 59 s