One R Function A Day.

February 11, 2013

(This article was first published on Category: R | Huidong Tian's Blog, and kindly contributed to R-bloggers)

As a R user with 5 years experience, I still have some basic functions that never used or never thought they could exist. Many times I was suprised with some elegant R functions, such like strwidth, parent.frame, etc. No one can know all R functions (and it’s unnecessary), but it’s very convenient to know some basic functions, especially those in the basic packages: base, utils, stats, etc.

I used to have a learning plan: learn one R function a day. But it was terminated because I always fail to remember it. Today, once again I found a useful function of the basic package base, which impelled me to keep learning R as a daily work. How could one guy who said he has 5 years experience but still doesn’t know some basic functions?!

My plan is simple: everyday I log on my computer, one of the first tasks is reading one topic-help document. To avoid forgetting to do this, I need the help page appears automatically.

So, I need to build a topic list first, and I want to start with the base package. The following is my code:

Topic List
URL &lt;- “<em>1 &lt;- readLines(URL)
ptn &lt;-&lt;a href=\”.*?.html\”&gt;(.*?.html)&lt;/a&gt;xmlem>2 &lt;- regmatches(xml<em>1, regexec(ptn, xmlem>1))p>

<p>html.list &lt;- NULL
for (i in 1:length(xml<em>2)) {
  if (length(xmlem>2[[i]]) == 2) {
    html.list &lt;- rbind(html.list, xml_2[[i]][2])
html.list &lt;- sort(unique(html.list[-which(html.list ==00Index.html”)]))

Then I need to choose an order to load the topic one by one. The function parent.frame(2)$ofile is used to get current script’s absolute path.

One by One
i = 0
browseURL(paste(URL, html.list[i + 1], sep = “”))
x &lt;- paste(“i”, i+1, sep =&lt;-)
cur_code &lt;- readLines(parent.frame(2)$ofile)
cur_code[grep(^i “, cur_code)] &lt;- x
writeLines(cur_code, parent.frame(2)$ofile)

The last step is creating a .bat file to run the R code in a batch mode, and add that file to your Task Scheduler and set the trigger as “at log on”. The content of the .bat file looks like this:

Batch Mode
 R CMD BATCH C:\Packages\base_help.R

Any kind of criticism or commet are welcome!

To leave a comment for the author, please follow the link and comment on their blog: Category: R | Huidong Tian's Blog. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


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)