[R] Use trelliscopejs to arrange plots
Trelliscope is an R package which interfacing a Javascript library trelliscopejs. This library provides an visulization of data by splitting them into subsets, also called ‘Trellis Display’ or “small multiples”.
The R package provides some high-level functions such as facet_trelliscope() which can directly replace the function ggplot2::facet_wrap() when making plots. The advantage of the former is that it can create multiple pages of plots when there are many, but facet_wrap() will put them into one plot.
[blogdown] Enable Disqus comment in Hugo website
To enable disqus in a blog website, one need do setting in the configuration file ‘config.toml’.
Depending on the theme used by the website, one need set up the parameter ‘disqusShortname’, in the top level of the config file, or under ‘[params]’ section. The best place to check this is to read the theme’s github page for configuration. For the theme ‘diary’, it need be under ‘[params]’, as below:
1 2 [params] disqusShortname = "fortune9-netlify" To get ‘disqusShortname’, one need visit https://disqus.
[Linux] How to preserve environment variables in `sudo`
When one runs sudo, he actually starts a new environment as the root user, so any environment variables in current shell environment will not be transferred to the new root user environment.
To transfer current environment variables to the new environment, one can run the following command:
1 2 3 curVar="variable in current environment" sudo -E echo $curVar # output: "variable in current environment" Here the option -E lets the sudo to preserve user’s environment, so the variable curVar is visible in sudo.
[R] fix and update blogdown hugo theme
Today, I fixed one big issue in my blog – the missing ‘google fonts’, from which I learned a lot, and I will share here and hope the experience to help others.
The issue As you will see from the two pictures below, the left one shows the google fonts as their words (see the items in the red loop), such as ‘chevron_right’ and ‘brightness_7’. And the picture on the right is correct.
[Blog] theme lost in Netlify deployment
Yesterday, I wrote a blog in Rmarkdown and pushed it to github for automatic deployment in Netlify.com.
Although the website was displayed correctly, it was not in the deployed website – the text were shown in disorder and the theme seemed not used.
I guess that the following issues may cause the problem:
in that Rmarkdown post, I used javascript code to change the page layout (adding a footer).
[R] Add a footer to the outside of rmarkdown html main-container
Normally, in the html output of an Rmarkdown document, the <body>...</body> tag encloses a <div>...</div> with class ‘main-container’ which hold the main content. When one add a footer with the following YAML header, it will appear at the bottom of the page as expected:
1 2 3 4 output: html_document: includes: after_body: resource/footer/banner.html However, this may lead to problems when the main-container is in a frame or a mini-page: the added footer will fill to the width of the frame, but not to the width of the page.
A new test post
Netlify deployment lost my theme, so I want to see whether this post can trigger a new deployment to recover it.
[Linux] How to tell a bash script is sourced or executed?
In bash, a script can be both executed and sourced.
An example script as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 #!/bin/bash if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then echo "I am being executed" sourced=0 else echo "I am being sourced" sourced=1 fi # this variable setting has no effect if executed, because # the execution is in a sub-shell export VAR_SOURCE="Only effective if sourced" if [[ $sourced -gt 0 ]]; then echo "Done in source" return 0 else # call exit when sourcing a file will exit the terminal echo "Done in execute" exit 0 fi Distinguish between the two To tell whether a script is being sourced or not, one can use the test [[ "${BASH_SOURCE[0]}" == "$0" ]], where ‘${BASH_SOURCE[0]}’ is the current script filename, and ‘$0’ is the same if being executed but empty string "" if sourced, as shown in the above code.
[R] Install multiple versions of R
how to install multiple versions of R in a system
[github] store github credentials securely
As a developer, I tried to do things efficiently. One thing that I want to fix is avoid input the password (or personal access token) when push to github. Actually, this is not an easy problem because I did not find a comprehensive webpage to provide step by step guide on how to achieve this goal. After researching this issue for one day, finally I could push to github without inputting any password, and I want to share how I achieved this to help anyone who may struggle for this.