GNU C “Nested Functions” Extension and Trampoline

Required background knowledge: activation record, static scoping & dynamic scoping.

Below is not standard C code. (case1)

foo (double a, double b){
  double square (double z) { return z * z; }    
  return square (a) + square (b);
}

Read more

R Write a Date Frame to CSV File

In R, we can easily write a date frame object to a csv file. By using the method write.csv, the csv file can be generated under the same directory of your R script. write.csv(dataFrame, file=”median.csv”)

Install R on Mac

Installing R on Mac is very easy. Just download the installation file here: http://cran.r-project.org/bin/macosx/. The bin files will be automatically added to the PATH.

Install R on Windows

Installing R on Windows is pretty straightforward. Just go to the page and download the installation file here. Remember you need to add the bin directory to your “Path” environment variable.

Get Argument Value from Command Line in R

Sometimes, you may want to run R Script by using command line. In this way, you can write a bash script and schedule a task everyday. In addition you can also pass different arguments to the R program. Create a R script “GetARgument.R”: args

Read File in R Line by Line

The R code below reads a file line by line. path <- "/path/to/the/file" print(path)   conn <- file(path,open="r") lines <- readLines(conn) for (i in 1:length(lines)){ print(lines[i]) } close(conn)path <- "/path/to/the/file" print(path) conn <- file(path,open="r") lines <- readLines(conn) for (i in 1:length(lines)){ print(lines[i]) } close(conn)

Backreferences in Java Regular Expressions

Backreferences in Java Regular Expressions is another important feature provided by Java.

To understand backreferences, we need to understand group first. Group in regular expression means treating multiple characters as a single unit. They are created by placing the characters to be grouped inside a set of parentheses – ”()”. Each set of parentheses corresponds to a group.

Read more