Articles by Kun Ren

Tips on non-standard evaluation in R

December 2, 2014 | Kun Ren

One of my favorite features of R is its meta-programming facilities. It can be simply demonstrated by the following examples. An ordinary use of R is to do statistical computing. We can evaluate something like
<span>sin</span><span>(</span><span>0</span><span>)</span>
[1] 0
Meta-programming in R allows users to manipulate the expression to evaluate. We can ... [Read more...]

pipeR tutorial is released

September 21, 2014 | Kun Ren

Twelve days after the initial commit, pipeR tutorial is released! If you want to write R code fluently and process data elegantly, I strongly recommend that you read this tutorial which is designed to serve as a complete guide to pipeR package, inclu... [Read more...]

More operators or more syntax?

August 22, 2014 | Kun Ren

The motivation of pipeline operator is to make code more readable. In many cases, it indeed better organizes code so that the logic is presented in human-readable fluent style. In other cases, however, such operators can make things worse. Recently, I had an interesting discussion on how to add side ... [Read more...]

Easier way to chain commands using Pipe function

August 15, 2014 | Kun Ren

In pipeR 0.4 version, one of the new features is Pipe() function. The function basically creates a Pipe object that allows command chaining with $, and thus makes it easier to perform operations in pipeline without any external operator. In this post, I will introduce how to use this function and some ... [Read more...]

Difference between magrittr and pipeR

August 7, 2014 | Kun Ren

(This post is rewritten to adapt to the latest release of pipeR) Pipeline is receiving increasing attention in R community these days. It is hard to tell when it begins but more people start to use it since the easy-and-fast dplyr package imports the magic operator %__% from magrittr, the pioneer ... [Read more...]

A quiz on magrittr: How many scores can you get?

August 6, 2014 | Kun Ren

Here is a quiz on magrittr and you may check if you are really good at using it. Since the CRAN version currently does not support nested ., it won't be interesting to make a quiz on that version. All the following examples are using the latest development version on GitHub. ... [Read more...]

Introducing rlist 0.3

August 5, 2014 | Kun Ren

rlist 0.3 is released! This package now provides a wide range of functions for dealing with list objects. It can be especially useful when they are used to store non-tabular data. Two notable features are added in this version. First, list.search and equal() are added in support of fuzzy filtering ... [Read more...]

Introducing pipeR 0.4

August 3, 2014 | Kun Ren

pipeR 0.4 is released! Check it out at the project page. In this new version, two things happen. First, %____% handles everything. Second, the introduction of Pipe object. %____% In version 0.4, I decide to merge the functionality of all three operators in the previous versions. Only %____% operator remains, and the two other operators ... [Read more...]

Scraping information of CRAN packages

July 28, 2014 | Kun Ren

(This article is adapted to the latest version of rvest package.) In my previous post, I demonstrated how we can scrape online data using existing packages. In this post, I will take it a bit further: I will scrape more information of CRAN packages since each of them also has ... [Read more...]

What are the most popular keywords of CRAN packages?

July 24, 2014 | Kun Ren

(This article is adapted to the latest version of rvest package.) A large proportion of R's power should be attributed to the enormous amount of extension packages. Many packages are published to CRAN. These packages cover a wide range of fields. In this post, I'll show you how to use ... [Read more...]

rlist: a new package for working with list objects in R

June 25, 2014 | Kun Ren

In recent years, non-relational data have attracted more and more attentions. Roughly speaking, all datasets that are hard to put into a rectangular table with rows and columns are non-relational datasets. The following data is a very simple non-relational dataset in JSON format. The dataset contains some information of three ... [Read more...]

A new gitbook – learnR

May 30, 2014 | Kun Ren

Gitbook is rather a relatively new concept on the web. It provides a user-friendly framework for authors to write and produce online books with beautiful illustrations and responsive interactions. It allows authors to write in Markdown syntax, which is very easy to learn and use, so that they can focus ... [Read more...]

Use pipeline operators in R

April 7, 2014 | Kun Ren

In data-driven statistical computing and data analysis, applying a chain of commands step by step is a common situation. However, it is neither straightforward nor flexible to write a group of deeply nested functions. It is because the function that comes later must be written first. Consider the following example ... [Read more...]

Reshape R data frame from long to wide format

March 13, 2014 | Kun Ren

Oftentimes, we obtain a long or a wide table from a certain data source, and it may be the only format we can get. For example, some financial databases provide daily tick data for all stocks in a financial market. The data table may be arranged in a long format ... [Read more...]

Extract information from texts with regular expressions in R

February 19, 2014 | Kun Ren

People love dealing with well-structured data. It costs much less efforts than working with disorganized raw texts. In economic and financial research, we typically download data from open-access websites or authentication-required databases. These sources may provide data in multiple formats. For example, almost all databases are able to provide data ... [Read more...]

A principle of writing robust R program

February 14, 2014 | Kun Ren

Writing R code can be very easy. It depends on how much you want to achieve with your code and what features you want your code to support. To test a random thought that needs some statistical evidence, you only need to casually import data, slightly transform the data to ... [Read more...]

Use SQL to operate R data frames

February 6, 2014 | Kun Ren

In both research and application, we need to manipulate data frames by selecting desired columns, filtering records, transforming and aggregating data. R provides built-in functions for data frame manipulation. Suppose df is the data frame we are dealing with. We use df[1:100,] to select the first 100 rows, df[,c("price","... [Read more...]

Introduction to parallel computing in R

January 31, 2014 | Kun Ren

For R beginners, for loop is an elementary flow-control device that simplifies repeatedly calling functions with different parameters. A possible block of code is like this:
run <span><-</span> <span>function</span><span>(</span>i<span>)</span> <span>{</span>
  <span>return</span><span>((</span>i<span>+1</span><span>)</span><span>/</span><span>(</span>i<span>^</span><span>2+1</span><span>))</span>
<span>}</span>
<span>for</span><span>(</span>i <span>in</span> <span>1</span><span>:</span><span>100</span><span>)</span> <span>{</span>
  run<span>(</span>i<span>)</span>
<span>}</span>
In this code, we first define a function that calculates something, and then run the function from i = 1 to i = 100. This can be ... [Read more...]
1 2

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)