domenica 26 luglio 2009

Rosetta Code

Today I'd like to suggest the interesting Rosetta Code site:

Rosetta Code is a programming chrestomathy site. The idea is to present solutions to the same task in as many different languages as possible, to demonstrate how languages are similar and different, and to aid a person with a grounding in one approach to a problem in learning another.

Since the R coverage of the different tasks is still largely incomplete, I encourage everyone to populate the missing tasks with appropriate R code.

venerdì 3 luglio 2009

File Management in R: two recipes

Remove files with a specific pattern in R:

A quick basic tip which can come in handy whether you need to rapidly remove files from a directory:

junk <- dir(path="your_path",  pattern="your_pattern") # ?dir
file.remove(junk) # ?file.remove

Compress multiple files/folders in separate zip files:

This tip came handy to me when I had to compress into separate .cbz files (zip files with an other extension) a vast collection of folders containing scans for different numbers of a comic book series (to create .cbz files instead of zip files, just substitute .cbz to .zip in the following code).

l=basename(list.dirs(recursive=F))
for (i in 1:length(l)) zip(paste(l[i],".zip",sep=""),files=l[i]) # ?zip

Clearly, for advanced needs, you can use system() and all the unix tools installed onto your machine.

Note: This post was updated on 1/5/2012