Wednesday, March 7, 2012

Some time conversions in R

Form a "POSIXlt" object from a string :
tt = strptime("20100101","%Y%m%d", tz="GMT")

Compute the seconds since 1970 ((Internal storage format of the "POSIXlt" class)
as.double(tt)

Compute the days since 1970 (Internal storage format of the "Date class)
as.double(as.Date(tt))
or
unclass(as.Date(tt)) 

Convert an xts object into seconds since 1970
xx = xts(111, tt)
as.double(time(xx))

Convert an xts object into days since 1970
floor(as.double(time(xx))/60/60/24)

Construct a time object from different numeric components
ISOdatetime(year, month, day, hour, min, sec, tz = "")

Extract from a POSIXlt object the Year, month, day  etc information in numeric format :
class(a)
[1] "POSIXlt" "POSIXt"

a
[1] "2009-07-06 20:00:28"

c(a$year+1900, a$mon+1, a$mday, a$hour, a$min, a$sec)
[1] 2009    7    6   20    0   28

Convert a ESRI shapefile into GMT vector format

Use ogr2ogr to convert the shapefile into GMT vector format :

ogr2ogr -f "GMT" Hudson_bounds.gmt  Hudson_bounds.shp

Wednesday, February 29, 2012

Switch the layout of your keyboards

Handy switch if you need to change regularly between layouts of keyboards.


Setxkbmap is a tool to set the keyboard layout. In the options of the tool you're allowed to set a switch.

setxkbmap -option grp:switch,grp:alt_shift_toggle,grp_led:scroll be,us

sets the keyboard to belgium (be) and with alt+shift I can switch to a us layout.

You can find the explanation for the coding in:

/usr/share/X11/xkb/rules/xorg.lst

You might want to execute this command autocratically on login, so you don't have to type it all the time again.

create a file "setxkbmap.desktop" in "~/.config/autostart/"

nano  ~/.config/autostart/setxkbmap.desktop

and enter the setxkbmap command

[Desktop Entry]
Encoding=UTF-8
Name=sertxkbmap
GenericName=set keyboard layout
Comment=Switch with alt+shift the layout of your keyboard
Exec=setxkbmap -option grp:switch,grp:alt_shift_toggle,grp_led:scroll be,us

this file will be run every time you login to your system

Tuesday, February 28, 2012

Changing the filename extension in R

Filenames ending with *.bin or *.txt will be given the extension *.grd. Applies to a character array containing multiple strings

outFileName = gsub("\\.bin|\\.txt", ".grd", inFileName)

Saturday, February 18, 2012

Ubuntu keyserver

If you have a keyserver error after adding a new repository try doing
 
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 16126D3A3E5C1192
 
replace 16126D3A3E5C1192 with the key of the repository you just added.

Thursday, February 16, 2012

Free tool for resizing a windows partition - EASEUS

EASEUS is free and works like a charm. It resizes a windows NTFS partition smaller than the size allowed by the Windows' own partition manager.

Tuesday, February 7, 2012

Reloading an updated R package without quitting R

Let us say that we worked on the source code of the package Cops and we would like to reload it  without quitting R

Re-install the package from Terminal 1 :
R CMD build Cops; sudo R CMD INSTALL Cops_1.2.tar.gz


Reload the modified package from the R session already running in  Terminal 2 :
detach(package:Cops,unload=T); library(Cops)