R-Graphics for Networks

With R you can make beautiful graphics and the nice thing is, you can design your own customized graphics. For some nice graphs produced with R, have a look at http://addictedtor.free.fr/graphiques/.
 
At the moment I am working on a parking model (searching for parking lots in the city) and have a simple grid for the streets and the junctions. If you start working with network models you have the problem that there is basic information for every node and on top of that you have for every node your results. Trying to interprete the results is hard. Either you have a huge excel sheet with lots of numbers for every node or you try to catch specific results in your model by filtering the output and looking at your model results listing.
 
R gives you the possibility to draw your network with all the information near the nodes. I first wrote all the numbers near the nodes with different colors, then I used arrows in different colors and different sizes. That was all nice, but still hard to read.
What I really wanted was to have something like a piechart or bars for every node directly plotted on the grid.
 
In R this is possible. You can use the x- and y-coordinates of your nodes and the drawing function polygon(). With some basic geometry (wihich I had to look up….) and ideas from Bálint Czúcz (http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=143) ,
I managed to write a R-script that takes the number of results per nodes (in my case 3, but you can have as many as you want), the grid size (in my case 5×5, but you can also use a real grid for a specific citiy). The script calculates the relative sizes of the results or basic information (for example number of old people, number of young people, number of adults = (0.3, 0.2,0.5)) and the relative size of the total (in node a we have the most people, in node b we have only 50%) and uses this information to draw scaled piecharts.
 
In the nex figure you see the results. You  now can easily see that in this case mose people live in the node with the coordinates (4,6) and that every group has about the same size.
 
 
Another way would be using bars:
 
 
Here is the most important of the code (pie chart)
 
 
 
Share

Directory Opus: A great Windows Explorer replacement

I experimented with different replacements for the Windows Explorer. I tried several free replacements, but finally decided to buy Directory Opus (“Opus”). It can be found at http://www.gpsoft.com.au/index.html. It costs about 90 US Dollar. It has a manual of over 700 pages, so you can probably imagine that it will have many features. I have been using Opus for several years now, but never took the time of configuring it properly for my needs. Yesterday I discovered a nice article by Andy  (http://www.asiteaboutnothing.net/c_dopus.html) who shows how to make Opus more user-friendly. It is a great article and I implemented almost all his ideas.
 
Here is a screenshot of my normal Opus view with some of its features highlighed
 
dopus1.png (800x676 pixels)
 
There are several display modes possible (Windows Explorer Style, Dual Horizontal (my favorite), Dual Vertical, Commander, etc.).
One of the “killer” features of Opus is the possibility of using tabs. I have my most often used folders as tabs (see callout in the figure). I now can easily jump to these folders. Another nice feature is the grouped listing of files (lower pane) . You can adjust the background colors (the orignal background color is white). More features are the possibility of defining your own menubars, macros and easy filtering.
 
A nice feature is the flat view. In this view all the files in a directory and its subdirectories are listed. The next figure shows the flat view in which I filtered for all the files with the extension “gms”. I often use the flat view to clean up a directory by grouping all the files according to their extension and then sorting them according to their svn status.
.
 
As you can see, I added a colum svn-status, so I can see if I have to commit my files (TortoiseSVN, the shell extension for Subversion nicely integrates with Opus: You can see the status also by looking at the file icons). I use the colums SVN Status for sorting according status. In one of the usergroup posts (http://resource.dopus.com/viewtopic.php?f=18&t=13293&p=68105&hilit=button+svn#p68105), is a post with how to add buttons in the menu bar with subversion commands (see first figure for the buttons). This allows me one click to commit, update or check the status of a file or directory (all subversion commands can be found by using right click too).
 
You can download a trial version for 60 days. There is a 32 and 64bit Version. Unfortunately, I don’t earny a penny if you buy Opus…
Share

Compiling LaTeX files to pdf: a second try

In a previous topic, I showed how to use a macro to kill your pdf-reader when you compile LaTeX files. Most pdf-readerss do not allow to refresh a pdf-file after compilation, so you have to close the file in the pdf-reader before compiling. My solution was to kill the pdf-reader completely. A reader of my blog wrote that you can use Sumatra, a free pdf-reader, which allows to refresh your pdf-file.
I decided to give it a try, but I wanted to keep my normal pdf-reader for all other pdf-files, because it has lots of options like commenting etc. I regularly use.
Another thing that bothered me with my pdf-reader is, that I could not jump back to Emacs (inverse-searching). Sumatra has this option.
Here are my settings in Emacs:
Sumatra will not reopen if you add the option -reuse-instance:
 Do not forget to set the inverse search command in the options of Sumatra to:
     c:\program files\emacs\bin\emacsclientw.exe +%l “%f”
Share

Using the identifier-list in Gams-mode

Gams-mode has lots of features and I am still amazed how powerful it is. I just discovered the use of the identifier-list (C-c C-a). I have a rather complex model with lots of include files and easily forget all the parameter names I use. Was it scale_mrd or mrd_scale? What was the name of the set HH or HHG? Here is where the identifier list comes in handy. Just hit C-c C-a and all the parameters, sets, variables appear as a new buffer.
 
 
 
 
You can change the way this information is listed. For example hit in this buffer “j” and all the information is grouped. You can hit the “+” or “-” sign to show or hide a certain group. Now you can work in your gams file and scroll or search through the identifier list. It is also helpful if you have forgotten to write the text describing an identifier: just scroll through the list and use “space” to jump to the identifier in you gams file and add the description. If you hit “enter” you jump to the identifier and the identifier-list buffer is closed.
 
Share

Adding Gams file extensions in gams-mode

In Gams-Mode all files with the extension “gms” are recognized as gams-files and all keywords are highlighted properly. You can add other extensions that should be recognized by setting the variable gams-file-extension.
An easy way to find this in Emacs is by going to “Options” – “Customize Emacs”  Settings matching regexp” where you search for gams-file-extension (it is in the group “gams”).
 
Just click INS and add your extension (I added inc as extension).
 
Do not forget to save your settings.
Share

Template Mode for Emacs

If you write a lot of R-, Stata-, Gams and/or LaTeX-files templates can make your life more relaxed. Emacs doesn’t have a template system (well there is auto-insert, but I did not find enough information on how to use if for templates). I used to have some templates in a directory and usually I would start with them (and forget that I should save it under another name…). The disadvantage is that you have to jump around in the file to fill out the information you want to have at the top of the file (like project name, topic, file name etc.). Today I discovered templatemode (see http://emacs-template.sourceforge.net/details.html). It works like a breeze and makes my writing life much easier.
 
I have templates for the above mentioned file types. The Gams template looks like this:
 
Now if I start a new file, TemplateMode asks me if I want to use the Gams-template, it inserts all the information between >>> and <<< or asks for information to insert. For example DIR, DATE will grab the directory and the date. At the end of the template file you see pairs of words. These words define the interactive part. Templatemode asks me for the project name with Project:, the job with Job: and the Gams title with Title:.
 
The line with the Version Control Information grabs information from my verison control system as soon as I commit the file (and is not part of templatemode).
 
This is how a new Gams file would look like:
 
 
Installation is easy and you can find lots of examples in the directory.
 
 
Share

Killing an open instance of pdf viewer when compiling latex

If there is one thing that is annoying when you us pdflatex in Emacs, it is the behavior of Adobe or another commercial product. If you haven’t closed the pdf-file, Emacs or better LaTeX will complain that the pdf-file is still open. I found some tricks in the internet, but I did not manage to implement them properly (you can for example use sumatrapdf, but I wanted to keep my original pdfreader on my computer).
Finally, I decided to use my macro/script program winautomation (www.winautomation.com). I bought this program a few months ago after getting tired of the open source program Autohotkey (which is quite good, but you have to program a lot). Winautomation is just point and click. I wrote a lot of macros that make my life much simpler. For example, I have some scripts that start my subversion backup on my servers, some scripts that open the explorer in a certain directory, a script for logging in at the university, etc.
 
 
For the problem above, I did two things: I wrote a script that checks if the pdf-viewer is open, and closes it and integrated it in an Emacs macro.
Here is the script in winautomation:
 
 
In Emacs I recorded a macro with C-x ( and C-x ) in which I run a shell command:
 
      Alt-x shell-command Enter
      d:\inbox\closepdf.exe             (this is the script I wrote with winautomation)
      C-c C-c                                 (starting latexing)
       …
 
After some trial-and-error, I now have a Emacs-keyboard macro that exactly does what I want: it closes the pdfviewer program using the winautomation-script and compiles my tex file to pdf.
I changed my settings for latex to always produce a pdf-file by putting the following line in my .emacs
 
      (setq TeX-PDF-mode t)
 
so now I don’t have to bother about the proper file-format for figures (no converting to ps, etc.).
 
The last thing I had to do was assign a key to my macro in Emacs. This is done by first naming the keyboard macro I recorded using “Alt-x name-last-kbd-macro” and after that save the macro in my .emacs file with Alt-x insert-kbd-macro and attach a key to it:
 
Here is the code snippet for the .emacs file
 
 
Of course, all this is also possible with autohothey or AutoIt,
Share

Starting Emacs in Full-Mode on Windows

Just a quick one: if you start Emacs on Windows (on probably also on other systems) it opens not in full-mode. After some googling I found this in the Emacs-FAQ  for the .emacs file:
 
(add-hook ‘term-setup-hook #’(lambda () (w32-send-sys-command ?\xF030)))
 
Simple but effective.
 
 
 
 
Share

Update of Gams-Tex

Edson Valle sent me an update for Gams-Tex (see my blog from 28. Januari) where he showed how to add new keywords to the Gams-Tex file (here done for the MPSGE keywords):
 
Just add the following lines to the gams theme file (theme_gams.tex) after the moreKeywords={
$PROD, $DEMAND, $AUXILIARY, $COMMODITIES, $SECTORS, $CONSUMERS, $MODEL, $REPORT,
It’ll become automatically case insensitive due to the options selected.
Share

OrgMode on my iPhone: MobileOrg and Dropbox

In one of my last year posts I wrote about using Org-Mode for organizing your projects and your notes/todo’s with links to your files. I am now using org-mode for lots of things but especially for my todo’s. Now this works fine if my notebook is up and running, but sometimes I want to have a look at those org-files without firing up my notebook. I use an iPhone and Richard Moreland developed a nice app (see http://mobileorg.ncogni.to/) that works together with dropbox (http://www.dropbox.com/).
 
 
It has some nice features:
  • Support for Dropbox or WebDAV as a transfer mechanism
  • Org files are stored offline and available anywhere
  • Complete editing support, including editable headings, body text, todo state, tags and priority.
  • Note-taking facility built in, including offline support
  • Full-text search, or search by keyword (TODO, DONE, WAITING) or by tag (errand, office)
  • Mark nodes as done, or flag them with an optional note for reference later
  • Document view of your outlines, for reading document-style Org files with long body text
  • Powerful support for linking between Org files

Here are some printscreens from my iPhone (by the way: printscreens can be produced by pushing the on/off and home button at the same time).
 
IMG_0045.PNG (320x480 pixels)IMG_0046.PNG (320x480 pixels)
IMG_0047.PNG (320x480 pixels)IMG_0048.PNG (320x480 pixels)
 
Share