[R] Need import S3 functions for a package to use
When developing an R package, it has been suggested to just put the dependent packages in Description file under Imports section.
However, I recently found that for S3 methods exported by a package, one need to import such functions explicitly in order to use them in the developed package. One example is the unique() function from the package data.table. This function can’t be called via data.table::unique(), because it is a S3 method.
[Thunderbird] Error: User is authenticated but not connected
Issue In last few days, my thunderbird striked: it frequently popped two error messages: “The service outlook.office365.com is disconnected” and “User is authenticated but not connected”.
Research After searching the website for a few days, I came to an solution, which was found here.
Solution Go to Settings -> Config Editor, and then search network.dns.disableIPv6 and click the toggle switch on the right to make it ‘true’. Finally close and reopen Thurderbird, and the problem should be resolved.
[AWS] How to use an IAM role via AWS CLI
There are situations that one may have multiple AWS accounts (or IAM roles) and need switch among them sometimes. This is doable via the AWS website by clicking the username button at the top-right and then click switch role.
How to do this in the command line?
To switch IAM roles via AWS CLI, one can do the following:
Edit the file ~/.aws/credentials The file ~/.aws/credentials stores the AWS credentials. It may include multiple profiles, in the following format:
How to disable Youtube shorts when uploading videos?
Recently, I need share a few videos via Youtube channel. However, the receiver said that the video continuously replayed itself.
The problem After some research, I noticed that the uploaded videos are short in length (less than 1 min), so these videos are marked as Youtube shorts video, and they automatically replay all the time.
Here is an example of short video with the URL https://www.youtube.com/shorts/nq-epMpa0E8
The fix As you can see in the URL, it has the format https://www.
[R] Include external script or child documents in Rmarkdown
When one Rmarkdown document is too big, one can consider split the file into smaller ones. In this post, I will introduce the ways for this purpose.
Include external R scripts There are two ways to include external scripts: using the functions source() or sys.source() or chunk option file.
Method 1: use source() or sys.source() 1 2 3 4 ```{r, include=F} source("external.R", local=knitr::knit_global()) # or sys.source("external.R", envir=knitr::knit_global()) ``` Note that one needs to provide local environment explicitly with knitr::knit_global(); otherwise it may report errors of objects not found.
[R] Automatic email sending with *blastula*
blastula is an R package that can be used to send emails automatically. In addition, it can render Rmarkdown documents into emails, which can be sent later. The main challenge is to setup smtp server. In this post, I will show how to setup smtp server and send emails afterwards.
One can find more on blastula at github.
Install blastula 1 install.packages("blastula") Setup smtp server Basically, one needs change settings in his email accounts to allow app-triggered actions, and this sometimes involves decreasing security levels, so may not be ideal.
[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.