sinx: R fortunes in Chinese

By Peng Zhao | March 6, 2019

One of the funniest things I found when I (as a Windows user) leant Ubuntu was that there is a command fortune, which prints a random/pseudorandom message from a database of quotations. It is said that this old feature has been available since 1970s. It was a pity that this feature was unavailable in boring Windows OS, until the R community developed in 2012 a package called 'fortunes,' which displays funny messages taken from the talks or communications in the R community. It supports external database as well. Unfortunately, it does not support Chinese texts, probably because (1) the 'fortunes' package cannot read multibyte characters such as Chinese, and (2) no one contributes Chinese database of fortunes.

It is a great loss, as fortunes actually come from Chinese restaurants.

R has been developing very rapidly in the Chinese community in recent years. There are online Chinese forums such as the Capital of Statistics, annually organized R conference in China, and numerous books on R. Many interesting 'fortunes' are hidden there. What if bring them into a 'fortunes'-like package? Or bring some more fun into it?

It is a pity that the 'fortunes' package is read-only. Therefore, I develop a brand new package, called 'sinx'. It displays fortunes in any language, only if a database is available.

The name originated from the name cosx, which is the domain of the Capital of Statistics. sin(x) is the derivative of -cos(x), or I would like to explain 'sinx' as 'Sino Xmen Said'.

I designed a logo for 'sinx', which can be printed on a T-shirt.

Briefly speaking, the current features of 'sinx' are as follows.

  • Like the 'fortunes' package, the main feature of 'sinx' prints randomly a Chinese message taken from the R community by default. See ?sinx().
  • External data bases can be imported into sinx. Users can customize their own fortunes in their favorite languages. See ?cscx().
  • One advantage of a 'sinx' database is that it can be organized either in markdown format besides the table format. Users can easily contribute good fortunes to 'sinx' via github. See the source database.
  • Another funny thing is 'cowsay'. The 'sinx' package can print messages in a cowsay way, which means that a colored pet can be displayed behind the sinx message. See ?tanx().
  • A useful feature is that users can easily convert a database into an E-book (demo) or slides (demo). See ?secx().
  • Users can easily choose whether to display a sinx message at the startup of R. See ?ctanx()
  • I have prepared six databases including famous poems in ancient China and famous sayings worldwide besides the default one.

Here is an example, which prints randomly a poem by the top poet Li Bai, in the cowsay mode (spoken by a frog):

libs <- read.sinxs(lib = c("tangshi", "songshi", "chinese", "yangsheng", "english","jinyong"))
tanx(sinxs.data = libs)
#> 
#> 
#>  ----- 
#> 风吹柳花满店香,吴姬压酒唤客尝。
#> 金陵子弟来相送,欲行不行各尽觞。
#> 请君试问东流水,别意与之谁短长。
#> 
#> --- 李白 (金陵酒肆留别) 
#>  ------ 
#>     \   
#>      \
#>         (.)_(.)
#>      _ (   _   ) _
#>     / \/`-----'\/ \
#>   __\ ( (     ) ) /__
#>   )   /\ \._./ /\   (
#>    )_/ /|\   /|\ \_(  [nosig]

More details can be found on the online documentation.

In the future, more features will be brought into 'sinx' as follows.

  1. Create more funny database.
  2. Develop an RStudio addin for users to easily contribute new fortunes.
  3. Create a new feature for quizzes. Let users fill blanks in the message.
comments powered by Disqus