Specifying the font in an R console - multiplatform solutions? - r

This is fairly mundane as R questions go, but I would like to specify the font in my R console. It's easy enough to do in Windows - John Cook has an excellent little writeup on that.
However, that is specific for the Windows R GUI. I'm not able to find a way to do this (at least from within R) on RStudio, Linux, etc. Is there a global, platform-agnostic solution? If not, what would need to be wrapped to make this feasible given per-platform idiosyncracies?
Or is this infeasible?
Note that I'm interested in the font family, rather than the font size, though font size suggestions are welcome.
Edit: I plan to apply this inside a program, if possible. Since R can make calls to the shell, I am happy with a two-pass method that first configures external files in preparation for a subsequent invocation of R, if that is necessary.

No, each of the front-ends to R are responsible for the way that the console is displayed to the user. This will be inherently platform and front-end specific.

I believe that Gavin is right: this is set per frontend, and I fail to find anything for Linux. However, the standard R frontend for Windows is addressed in my question. Mac users may find this page helpful: Permanently change default console font.
So, the answers as I found them may be summarized as:
Windows / default R - see John Cook's page
Mac - see link above
Linux / default R frontend - not possible (or am I wrong?)
(Windows, Mac, Linux) / Rstudio - Font family is not available (yet) - see this page. Font size is - this page
Windows / Revolution R - this page
Other / Revolution R - not found
So, the universal trick is that I need to use R via a web server, and then I can configure my browser. :) Not going to happen. I'll wait on Rstudio.

Related

How to embed maths in MediaWiki

I'm trying to transfer some maths content from and old wiki to my new MediaWiki.
The old page uses MathJax, and looks like this:
Here is the k-degree Taylor series for [[$ f(x) $]]
expanding around [[$ x=0 $]]
[[$ T_k(x) = f(0) + x\cdot f'(0) + \frac{x^2}{2!} f''(0) + \dots
+ \frac{x^k}{k!} f^k(0) $]]
This is what I've found so far:
http://www.mediawiki.org/wiki/Extension:MathJax -- appears to be discontinued.
http://www.mediawiki.org/wiki/Extension:SimpleMathJax -- I tried this and it works on OSX Chrome but gives rendering errors on OSX FireFox (https://github.com/jmnote/SimpleMathJax/issues/1)
http://www.mediawiki.org/wiki/Extension:Math -- this appears to be where the active development is occurring, but I haven't managed to get it working. Also it is a huge headache.
Have I missed anything?
What's the right way to enable maths content in a MediaWiki?
From what I can see, it is looking like: "render on server and provide PNG is faster, render on client using MathJax is simpler/cleaner"
SimpleMathJax is an absolutely minimal install. If only it worked on Firefox!
Math extension is looking like hard work, it looks like overkill -- it seems to support at least 4 different techniques for rendering.
A year after, the situation is getting even more confusing about how MediaWiki sites could process maths. If we all agree that texvc and maths formula displayed in png images are ugly and obsolete, it seems that Mathoid, according to https://www.mediawiki.org/wiki/Extension:Math, "is the most recommended option; Mathoid is the rendering mode that will be used on Wikipedia in the future.” .
But Mathoid requires an external server like Parsoid and they both (Mathoid and Parsoid) are in an heavy development. Therefore I looked for an other solution and found and tested successfully 'SimpleMathJax' (https://www.mediawiki.org/wiki/Extension:SimpleMathJax). It can be set like below
wfLoadExtension( 'SimpleMathJax' );
// MediaWiki 1.24 or earlier
// require_once "$IP/extensions/SimpleMathJax/SimpleMathJax.php";
works on any recent version of MediaWiki (latest version tested is mw1.28 of late December 2016).
However the code of the extension itself is not distributed with the numerous MediaWiki extensions from the WikiMedia fundation (which supports mathoid) but you can get it on github at https://github.com/jmnote/SimpleMathJax/archive/master.zip and expand it into your extension subdirectory with other extensions.
The math rendering is beautiful because it uses MathJax and MathJax (.org) is "an open-source JavaScript display engine for LaTeX, MathML, and AsciiMath notation that works in all modern browsers."
Most of the standard AMS LaTeX code seems to work fine (align etc).
It is called "simple" MathJax probably because it doesn't have the ambition of the MW MathJax extension to process all LaTeX and TeX facilities like numbering equations and process TeX macros, but it uses the original javascript CDN of mathjax.org and therefore is very simple to install and to use for short mathematical texts.
- If you want to process longer and even huge mathematical texts, you can try 'pandoc' which will transform your full LaTeX document into mediawiki source with the following command line:
$ pandoc -o foo.wiki -f latex -t mediawiki foo.tex
You do really want https://www.mediawiki.org/wiki/Extension:Math it is the standard way of doing things.
Maths rendering has been a problem on wikipedia for a long time now. The original system uses PNG images dates back to about 2005. It was the best that was available then, but it is really ugly, the font sizes don't match, the base line are all wrong and there is no anti-aliasing. The advantage is that its stable and works for all browsers.
Ever since then there has been attempts to improve the maths rendering. The first attempt was Blahtex which produced MathML but never got traction with the developers.
Then MathJax came along. The first implementation was as a user script
https://en.wikipedia.org/wiki/User:Nageh/mathJax this worked pretty well but needed the user to manually add it to their javascript skin files.
A couple of years ago MathJax got rolled into the main Math extension, with a user preference (off by default).
MathJax is the nicest current rendering but there are two major problems, browser support, it has to work on all possible browsers including the more limited ones on phones and ancient systems. The other is speed, as it is rendered by javascript it takes time to format the equations, this can be up to a minute for the more complex formula rich pages.
MathML is another possible option, however Firefox is the only browser with halfway decent support.
This has led to a problem with making a universal system. The current development is a system which allows client side MathJax/MathML rendering for those who want the best rendering, the old PNG rendering as a fallback and a new system which uses MathJax to render SVG on the server side.
As to what to actually do. I think the simplest is to ignore extensions completely and just use MathJax on the global javascript files. See https://en.wikipedia.org/wiki/Wikipedia:Common.js_and_common.css. This would be a pretty standard MathJax configuration.
Lets look at how the User:Nageh/mathJax script works, and adapt this for your setting. What he did is install a copy of mathjax on the webserver server, in his case it was all installed in his user space
https://en.wikipedia.org/w/index.php?title=Special%3APrefixIndex&prefix=Nageh%2FmathJax&namespace=2
If you have access to the server you could install the code in a more sensible place. Say for sake of argument MediaWiki/includes/MathJax. Then in common.js just have a line
importScript("/MediaWiki/includes/MathJax/MathJax.js");
or possible better
mw.loader.load("/MediaWiki/includes/MathJax/MathJax.js");
or even better
mw.loader.using("/MediaWiki/includes/MathJax/MathJax.js").done( function() {
MathJax.Hub.Config( ... );
} );
after than just have the MathJax hub setup you need. See https://www.mediawiki.org/wiki/ResourceLoader for details.

Can I access the colours of the R console, from R code?

I sometimes have up to 4 sessions of R, each running a different piece of software, between which I must change often. It would be helpful if the colour of the console background (or text) were to be different depending on which code was loaded, automatically, so that I could locate the window easily on my (cluttered) desktop and avoid typing in the wrong commands into the wrong console in my fast moving financial activities.
Any way to do this from within R code? Currently I am menuing up and changing the colours manually but it's tedious, especially that, under Windows, the R colour dialogue box is 4 lines deep and there are something like 500 colours.
This is not a direct answer to your question, but it might still be helpful. I like using multiple workspaces to solve this problem. If you have different R sessions running, having them on different workspaces (or desktops) separates them nicely. The platforms I work on (OS X and Linux) have native support for this workflow, but there must be tools like this for Windows (a few years back there where at least).

Do any R IDEs support conditional breakpoints?

Which, if any, R IDEs (e.g. StatET, Revolution R, RStudio, ESS, NppToR, others) support conditional breakpoints?
This is available via bp in the debug package, or via an additional bit of code that invokes browser() based on a condition. However, it can be more efficient to be able to toggle a particular line # and quickly enter a conditional breakpoint for that particular line, without having additional code or console activities.
Note 1. I've searched a bit for these, and it seems that conditional breakpoints are not available in RStudio, and I think the same may be true for StatET. There appears to be support in ESS (see this page), though I'm not yet familiar with ess-tracebug and whether it's easy to use. It also seems that this works only for older versions of ESS; I'm not yet familiar with functionality for more recent versions.
Update 1. I'm selecting an answer (the only one - Andrie's). The question was answerable regarding whether any IDE supports conditional breakpoints, and, fortunately, Andrie has demonstrated that there exists a solution. I remain interested in any other IDEs that support this, though Eclipse is good enough for now. (At the moment, I prefer Rstudio, but this is already in their feature request list.) If anyone has expertise in ESS and can demonstrate that functionality, I'm sure it will benefit others who happen upon this question.
Yes, this is possible with Eclipse + StatET 2.0 in R 2.14-1.
Eclipse supports conditional debugging, and StatET 2.0 supports visual debugging (as long as you have a fairly recent version of R.)
Assuming you know your way around Eclipse, do the following:
Start a debugging session in Eclipse (i.e. invoke a Debug configuration, not a Run configuration)
Set a breakpoint in your code
Open a Debug perspective
Run your code
With the debug perspective open, you will have a pane that contains tabs for Variables / Breakpoints. In the breakpoints tab, select your breakpoint, then click the Conditional / Expression tickbox and enter your condition.
In searching for this answer, I found the following pages helpful:
Download and install StatET
How to start a debugging session in StatET
How to set a conditional breakpoint in Eclipse
There is a little trick to set a conditional breakpoint in rstudio:
for(i in 1:10){
if(i==5){
print("set the breakpoint at this line by shift+f9")
}
i*i
}
The only drawback is you need to add some extra code
The preview release of RStudio v0.98 has this feature:
http://www.rstudio.com/ide/docs/debugging/overview
Only drawback is your function should be in the same file with your main code if you want to set a breakpoint in your function.

Is it possible to get code completion for R in Emacs ESS similar to what is available in Rstudio?

Rstudio has a great code completion feature. It provides a quick view of functions that start with a given string, as well as function and parameter definitions.
ESS is powerful enough, familiar to me, and integrated into Emacs, where I conduct most of my work - so I am hesitant to move, but this feature is making me consider such a move.
Is it possible to integrate this feature into Emacs ESS?
Is there anything similar to this for Emacs ESS?
Any hope that there will be (and if so, how could I support such an effort?)
You do get the completion thanks to the rcompgen package by Deepayan (now "promoted" into base R as part of the utils package). So when I type
lm(
and hit TAB a new buffer opens which gets me the left-hand side of your window above: the available options to the function at hand. I don't think you can show the help directly though.
There is / was also a way to get context-sensitive help in the mini-buffer when typing but I have forgottten how/where that gets turned on.
[EDIT: This is an old answer and auto-complete package dropped out of fashion since then. Please use company-mode instead. It should work by default. Wiki configuration entry is here.]
Recent versions of ESS (> v.12.02) integrate with auto-complete package out of the box (you need not configure anything, just install auto-complete). It provides help on arguments as well as function help. I added detailed instructions to the wiki
Ess-eldoc was also rewritten and from v.12.02 it's active by default, so you don't need to configure anything.
Or maybe we should all use search:
Emacs autocomplete-mode extension for ESS and R
I don't want to be grumpy, I found this few hours ago and I'm still shocked. It works like a charm. Though I still prefer the old-style pop-ups. =)

Ada: plotting 2d graphs

it would be interesting to be able to plot a 2D graph within an Ada code rather than having to save values say to file and use an external drawing software afterwards. A search on the web has taken me to two packages: Win_IO and JEWL. I have been able to use WIN_IO though but the documentation is quite poor and having just started using it, it seems that it is not possible to resize the size of the canvas. I use the GPS editor and I get complaint when running Win_IO that some fonts are not available on my system and that the output will be ugly. Finally the plot doesn't itself pop up on the screen; One has to click on the exe file of the file being compiled and linked so as to get the graph.
I have taken a look also at JEWL but it doesn't seem to be able to plot graphs.
Are there more Ada packages available out there for plotting 2D graphs.
Thanks a lot...
My experience with GNAVI:
The installation instructions are at
http://www.gnavi.org/index.php?Command=Class&ClassID=Start&CID=381
Basically the installation consists of:
To use:
Place this directory on your path
cd to gnatcom and run: make install
cd to gwindows and run: make UNICODE=1 all
run: gnavi_ide and enjoy :-)
But the installation is plagued with errors:
C:\gnavi\gnatcom>install
Installing GNATCOM.....
MAKE Version 5.2 Copyright (c) 1987, 2000 Borland
Error makefile 2: Command syntax error
* 1 errors during make *
Install Completed
C:\gnavi\gwindows>make UNICODE=1 all
MAKE Version 5.2 Copyright (c) 1987, 2000 Borland
Error makefile 2: Command syntax error
* 1 errors during make *
And though C:GNAVI is on my path, the IDE still complains that icg.exe which is found in C:GNAVI is not on the path.`This is trouble with software which has not been fully tested!!! I was very disappointed that people can write irresponsible and incomplete installation instructions. Have the developers even found out that whether a normal user can install their software?
I have also try to look at AdaDesigner at https://gna.org/projects/adadesigner
Here, FireFox complains: This Connection is Untrusted
gna.org uses an invalid security certificate.
The certificate is not trusted because the issuer certificate is unknown.
I decided not to visit such a website.
PLplot is a cross-platform package for creating scientific plots. It has a well-documented Ada binding. For reference, this gallery illustrates a variety of plots. Click a thumbnail to view a full-size image. Click either Ada tab (standard or traditional) to see the corresponding source code.
I'd give a try to GTKAda. I'm not completely sure this subsystem would allow you to do 2D graphs as I've never used it for that purpose, but it can be done with GTK+ (C/C++).
There is also a guide on GTKAda and a reference manual, some documentation on the GTK toolkit itself may also come handy.
It depends on exactly what you want to do. For graphing node-based diagrams, the first thing I'd look into using is Graphviz. It has its own special graphing language it uses, but I'm all about using Domain Specific Languages when appropriate. Ada has great interoperability, so using DSLs with it can really make it powerful.
An example I found is AdaDesigner, which generates Graphviz DOT files to help visualze the structure of Ada code.
The one time in the past I had to do simple plotting, it was for a web app. I ended up dynamically generating SVG pages on the server side (even though it was poorly supported then). Support is better now, so I'd definitely use it again today.
If working directly on a Windows PC display appeals more to you, there are several options for GUI bindings, all of which should support drawing lines and points on a canvas. In addtion to GTK (which is both powerful and portable), there are a few Win32 API's floating around. I think one comes with Gnat. Another you might not be aware of is GWindows. It is part of GNAVI, which aims to be sort of an OpenSource alternative to Delphi. It isn't the most active of projects, but is (reportedly) quite useable, and is still being worked on and used. Here are some screenshots of it being used for plotting.
(source: gnavi.org)
MathGL is cross-platform GPL plotting library. It have C interface, so you can use it from yours code too. Also it can create a window with graphics -- i.e. you don't need to study/use other widget libraries in simplest case.

Resources