How can I find all R packages that include graphics functions? - graphics

I always have difficulty in finding all available alternative ways to produce a specific graph, either one that I have already decided to use (looking for different variations) or one that I have not yet thought of.
The R Graphical Manual site provides a complete list of samples of R's graphics functions, however it's easier for me to search providing a package name (how else -for example- can I get a resultset including superbarplot function, when I want to look for barplots?. Let alone that the superbarplot graph does not appear in the results even if I try searching for it's package: UsingR)
The R-SAS-SPSS Add-on Module Comparison - and especially on topic Graphics, Static in the table provided - gave me the idea that it would be nice to have a place where all relevant packages are listed by topic.
Do you have any idea about something like that?

If you're interested in learning about all the possible graphics you can make, you should learn about the grammar of graphics, and (my) implementation of it in R: ggplot2.

Your question, or the general pattern anyway, was clearly a primary use case for the design of the sos package.
sos actually goes one step further that your question requires by identifying particular functions with packages; in addition, it ranks the results by relevance (by default, you can change the default behavior via the "sortby" parameter, e.g., sortby="Date")
Here's how it works:
most of this package's functionality is exposed via the "findFn" command
for instance, if you want a list of all functions and the parent package related to scatter plots:
findFn("scatter plot", maxPages=2, sortby="TotalScore")
This returns a dataframe formatted as HTML table and delivered in your default browser (if you don't want it to pop-up immediately, then just bind the function call to a variable and then call the variable when you're ready)
The right-most column of the dataframe/HTML page is "Description and Link". Clicking an entry in that column opens another tab in your browser (according to the user-set preferences set in your browser) with the complete R help page for that function.
The results from the function call above show, for instance, that the functions for plotting data in a 'scatter plot' format are found in the following packages:
ade4 (function: scatter)
IDPmisc (functions: ipairs, iplots)
GGally (function: ggally_points)
PerformanceAnalytics (function:
chart.Scatter)
mclust (function: clPairs)
Another example:
findFn("boxplot", maxPages=2, sortby="TotalScore")
identifies these (among others) packages/functions for plotting boxplots:
sfsmisc (function: boxplot.matrix)
aplpack (function: boxplot2D)
NADA (function: boxplot-methods)
StatDA (function: rg.boxplot)
plotrix (function: gap.boxplot)
gplots (function: boxplot.n)
multcompView (function:
multcompBoxplot)
oligo (function: boxplot)

Have you seen the R Graph Gallery ?
Other than that, you may have to index all the source code of CRAN packages to search efficiently...

these are good memory-joggers. I second the ggplot2 recommend, also recommend looking thru CRAN views:
http://cran.r-project.org/web/views/
http://cran.fhcrc.org/web/views/Graphics.html
(this mirror seems faster in west coast US)
http://dataspora.com/archive/2009/seminar/Survey_of_R_Graphics_by_Driscoll_Dataspora_Jun2009.pdf
http://zoonek2.free.fr/UNIX/48_R/04.html
(possibly world's longest webpage)
http://www.stat.auckland.ac.nz/~ihaka/120/lectures.html
Ihaka's lectures notes

Related

configure sort order in sublimetext3

I know how to sort lines in Sublime (ctrl+p "sort"). The problem is it doesn't sort some characters as I want, namely åäö.
Is there some way to change how sublime orders the text? Perhaps by a specific locale? It would also be interesting to be able to sort V and W as being equal.
Example: I want the following words to be sorted in this order:
bår
bär
bör
but Sublime sorts it like this:
bär
bår
bör
There has been a similar request logged on ST's issue tracker: https://github.com/SublimeTextIssues/Core/issues/1324
One of the ST developers replied:
Sorting in Python 3 uses Unicode code points as the basis for sorting. Sublime Text doesn't know what language your encoding represents, so it doesn't use locale-based sorting rules.
This seems like it is probably best solved by a package dedicated to providing locale-based collation rules.
Using https://packagecontrol.io/packages/PackageResourceViewer, we can see that the case_sensitive_sort method in Packages/Default/sort.py uses Python's built in list.sort method. Typing the following into ST's Python console (View menu -> Show Console), we get the same result as you have shown:
>>> a = ['bår', 'bär', 'bör']
>>> a.sort()
>>> a
['bär', 'bår', 'bör']
So the answer is that there is no setting to configure the sorting behavior, and nor is there likely to be in future. However, according to https://docs.python.org/3/howto/sorting.html#odd-and-ends, it is possible to use a locale-aware sort using locale.strxfrm as a key function.
Let's try. On Windows, I had to use
>>> import locale
>>> locale.setlocale(locale.LC_COLLATE, 'sve')
'Swedish_Sweden.1252'
to get Python to use a Swedish locale - as per https://stackoverflow.com/a/956084/4473405
>>> a.sort(key=locale.strxfrm)
>>> a
['bår', 'bär', 'bör']
Using this knowledge, you might choose to change the case_sensitive_sort method, so that ST's built in sort functionality (Edit menu -> Sort Lines (Case Sensitive)) will use the locale aware sort key. Note that saving the sort.py file opened from PackageResourceViewer will create an override, so that if future builds of ST include changes to sort.py, you won't see them until you delete the override (which you can do by finding the file using the Preferences menu -> Browse Packages -> Default. You can reapply your changes afterwards, if appropriate, using the exact same steps.)
You can also change the case_insensitive_sort method from
txt.sort(key=lambda x: x.lower())
to
txt.sort(key=lambda x: locale.strxfrm(x.lower()))
Note that, if your correct locale isn't picked up automatically (it probably defaults to C), then setting the locale in this (case_sensitive_sort) method isn't recommended, even if, immediately afterwards, you restore it back to what it was beforehand - so use at your own risk.
It is generally a bad idea to call setlocale() in some library routine, since as a side effect it affects the entire program. Saving and restoring it is almost as bad: it is expensive and affects other threads that happen to run before the settings have been restored.
You could instead add the following to the end of the sort.py file:
def plugin_loaded():
import locale
locale.setlocale(locale.LC_COLLATE, '')
which will, when the plugin is loaded, allow Python to infer the locale from your LANG env var, as per https://docs.python.org/3/library/locale.html#locale.setlocale. The advantage being you only set it once, and hopefully won't introduce any problems with other plugin code executing at the same time.
Happy sorting!

Converting an ASTNode into code

How does one convert an ASTNode (or at least a CompilationUnit) into a valid piece of source code?
The documentation says that one shouldn't use toString, but doesn't mention any alternatives:
Returns a string representation of this node suitable for debugging purposes only.
CompilationUnits have rewrite, but that one does not work for ASTs created by hand.
Formatting options would be nice to have, but I'd basically be satisfied with anything that turns arbitrary ASTNodes into semantically equivalent source code.
In JDT the normal way for AST manipulation is to start with a basic CompilationUnit and then use a rewriter to add content. Then ASTRewriteAnalyzer / ASTRewriteFormatter should take care of creating formatted source code. Creating a CU just containing a stub type declaration shouldn't be hard, so that's one option.
If that doesn't suite your needs, you may want to experiement with directly calling the internal org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteFlattener.asString(ASTNode, RewriteEventStore). If not editing existing files, you may probably ignore the events collected in the RewriteEventStore, just use the returned String.

How to find a source code (implementation) of a class in Haskell

I'm reading some documentation on IxSet's http://happstack.com/docs/crashcourse/AcidState.html#ixset , and I was wondering about looking at source of Indexable typeclass which is imported from Data.IxSet.
So then I took a repository of Happstack and looked there (darcs get http://patch-tag.com/r/mae/happstack), but that got me to even bigger frustration.
I see the happstack/happstack-ixset/src/Happstack/Data/IxSet.hs file, which creates a module Happstack.Data.IxSet, but I can't see which file creates a module Data.IxSet (and implements class Indexable).
The go-to address for Haskell code is hackage. There is conveniently a link to Hayoo on the front page, the other major Haskell search engine besides Hoogle. Both have advantages above the other.
Hayoo indexes all packages on hackage and the searches by default include all packages on hackage. If you want to search for a known name, e.g. Indexable, that is the more convenient engine, especially if you don't know which package the name comes from. The - currently - fifth hit takes you to Data.IxSet.Indexable. On the right hand side of the Haddock docs, you find a Source link that takes you to the hscoloured sources (in this case, that's not very informative, though, there's only one class member, without default implementation, it tells you nothing above the docs).
Hoogle searches only a small number of packages by default, if you want to include other packages in the search, you have to specify that by adding +packagename to the search - but that restricts the search to the specified package. More about Hoogle searches in the manual. Hoogle's strength is the search by type. Hoogle's search by type applies more transformations to the searched type, and thus finds more matches than Hayoo's if you don't know the exact type (that is not without downsides, however, sometimes you get a lot of irrelevant hits). If you search for example Map k a -> k -> Maybe a, Hoogle's first result is the most likely candidate Data.Map.lookup :: Ord k => k -> Map k a -> Maybe a, whereas Hayoo doesn't find that because it doesn't permute arguments.
Either way, both search engines lead you to hackage's Haddock docs for the queried entity (if the search was successful), from where the Source links take you to the code, if you wish.
Use Haddock documentation, locally-generated or online. Google search usually returns relevant docs near the top. The documentation is cross-linked so you can surf to the module you need. There's a link to the source next to each definition, for example.
This particular module belongs to the base libraries set.

How to get (translatable) strings from specific domain with POEdit

I have been trying for hours finding a way to setup POEdit so that it can grab the text from specific domain only
My gettext function looks like this:
function ri($id, $parameters = array(), $domain = 'default', $locale = null)
A sample call:
echo ri('Text %xyz%', array('%xyz%'=>100), 'myDomain');
I will need to grab only the text with the domain myDomain to translate, or at least I want POEdit to put these texts into domain specific files. Is there a way to do it?
I found several questions that are similar but the answers don't really tell me what to do (I think I'm such a noob it must be explained in plain English for me to understand):
How to set gettext text domain in Poedit?
How to get list of translatable messages
So I finally figured it out after days of searching, I finally found the answer here:
http://sourceforge.net/mailarchive/message.php?msg_id=27691818
xgettext recognizes context in strings, and gives a msgctxt field in the *.pot file, which is recognized by translation software as a
context and is shown as such (check image of Pootle showing context
below)
This can be done in 3 ways:
String in code should be in the format _t('context','string'); and xgettext invocation should be in the form --keyword=_t:1c,2
(this basically explains to xgettext that there are 2 arguments in
the keyword function, 1st one is context, 2nd one is string)
String in code in the format _t('string','context'); and xgettext invocation should be in the form --keyword=_t:1,2c
String in the code should be as _t('context|string') and xgettext invocation should be in the form --keyword=_t:1g
So to answer my own question, I added this to the "sources keywords" tab of Poedit:
ri:1,3c
ri is the function name, 1 is the location of the stringid, 3 is the location of the context/domain
Hope this helps someone else, I hate all these cryptic documents
(This is a repost of my answer to the same thing here.)
Neither GNU gettext tools nor Poedit (which uses them) support this particular misuse of gettext.
In gettext, domain is roughly “a piece of software” — a program, a library, a plugin, a theme. As such, it typically resides in a single directory tree and is alone there — or at the very least, if you have multiple pieces=domains, you have them organized sanely into some subdirectories that you can limit the extraction to.
Mixing and matching domains within a single file as you do is not how gettext was intended to be used, and there’s no reasonable solution to handle it other than using your own helper function, e.g. by wrapping all myDomain texts into __mydomain (which you must define, obviously) and adding that to the list of keywords in Poedit when extracting for myDomain and not adding that to the list of keywords for other domains' files.

How to number floats in LaTeX consistently?

I have a LaTeX document where I'd like the numbering of floats (tables and figures) to be in one numeric sequence from 1 to x rather than two sequences according to their type. I'm not using lists of figures or tables either and do not need to.
My documentclass is report and typically my floats have captions like this:
\caption{Breakdown of visualisations created.}
\label{tab:Visualisation_By_Types}
A quick way to do it is to put \addtocounter{table}{1} after each figure, and \addtocounter{figure}{1} after each table.
It's not pretty, and on a longer document you'd probably want to either include that in your style sheet or template, or go with cristobalito's solution of linking the counters.
The differences between the figure and table environments are very minor -- little more than them using different counters, and being maintained in separate sequences.
That is, there's nothing stopping you putting your {tabular} environments in a {figure}, or your graphics in a {table}, which would mean that they'd end up in the same sequence. The problem with this case (as Joseph Wright notes) is that you'd have to adjust the \caption, so that doesn't work perfectly.
Try the following, in the preamble:
\makeatletter
\newcounter{unisequence}
\def\ucaption{%
\ifx\#captype\#undefined
\#latex#error{\noexpand\ucaption outside float}\#ehd
\expandafter\#gobble
\else
\refstepcounter{unisequence}% <-- the only change from default \caption
\expandafter\#firstofone
\fi
{\#dblarg{\#caption\#captype}}%
}
\def\thetable{\#arabic\c#unisequence}
\def\thefigure{\#arabic\c#unisequence}
\makeatother
Then use \ucaption in your tables and figures, instead of \caption (change the name ad lib). If you want to use this same sequence in other environments (say, listings?), then define \the<foo> the same way.
My earlier attempt at this is in fact completely broken, as the OP spotted: the getting-the-lof-wrong is, instead of being trivial and only fiddly to fix, absolutely fundamental (ho, hum).
(For the afficionados, it comes about because \advance commands are processed in TeX's gut, but the content of the .lof, .lot, and .aux files is fixed in TeX's mouth, at expansion time, thus what was written to the files was whatever random value \#tempcnta had at the point \caption was called, ignoring the \advance calculations, which were then dutifully written to the file, and then ignored. Doh: how long have I know this but never internalised it!?)
Dutiful retention of earlier attempt (on the grounds that it may be instructively wrong):
No problem: try putting the following in the preamble:
\makeatletter
\def\tableandfigurenum{\#tempcnta=0
\advance\#tempcnta\c#figure
\advance\#tempcnta\c#table
\#arabic\#tempcnta}
\let\thetable\tableandfigurenum
\let\thefigure\tableandfigurenum
\makeatother
...and then use the {table} and {figure} environments as normal. The captions will have the correct 'Table/Figure' text, but they'll share a single numbering sequence.
Note that this example gets the numbers wrong in the listoffigures/listoftables, but (a) you say you don't care about that, (b) it's fixable, though probably mildly fiddly, and (c) life is hard!
I can't remember the syntax, but you're essentially looking for counters. Have a look here, under the custom floats section. Assign the counters for both tables and figures to the same thing and it should work.
I'd just use one type of float (let's say 'figure'), then use the caption package to remove the automatically added "Figure" text from the caption and deal with it by hand.

Resources