Posts tagged with programming

A question I’ve googled before without success. Hopefully this answer will show up for someone who needs it. I’ll also go over the better-known uses of ? just in case.

  • To get help in R about a function like subset you type ?subset . That’s like man subset from the command line.
  • If you only know roughly what you’re looking for use double question marks: so ??nonlinear will lead to the package nlme. That’s like apropos on the command line.
  • To get a package overview, type ?xts::xts. There is no ?xts help. Packages that don’t have ?twitteR::twitteR you will need to use ??twitteR to find the help pages on ?twitteR::status-class, ?twitteR::dmGet, etc.
  • Finally, the question of the title. To get R help on punctuation such as (, {, [, `, ::, ..., +, and yes, even on ? itself, use single quotes to ‘escape’ the meaningful symbol. Examples follow:
    • ?'`'
    • ?'('
    • ?'['
    • ?'...'
    • ?'+'
    • ?'%*%'
    • ?'%x%'
    • ?'%o%'
    • ?'%%'
    • ?'%/%'
    • ?'$'
    • ?'^'
    • ?'~'
    • ?'<-'
    • ?'='
    • ?'<<-'

All of the quotation marks `, ', " use the same help file so ?'"' or ?'`' will give you the help file for ?'''.




tl,dr: If you want to be contacted for freelance R work, edit this list https://github.com/isomorphisms/hire-an-r-programmer/blob/gh-pages/README.md.

 

Background/Problem: I was looking for a list of R-programming freelancers and realised there is no such list.

Other than famous people and people I already talk to, I don’t know even a small fraction of the R community—let alone people who do R among other things and don’t participate in the mailing lists or chatrooms I do.

This is actually a more general problem since anyone looking to hire an R programmer will find a wall of tutorials if they http://google.com/search?q=hire+an+r+programmer.

 

Solution: I thought about making a publicly-editable website where freelancers can put their contact info, specialty areas, links to projects, preferred kind of work, rates, and so on.

Of course, I’d have to make the login system. And validate users. And fight spam. And think up some database models, change the fields if someone suggests something better…. And it would be nice to link to StackOverflow, Github, CRAN, and …

The more I thought about it the more I favoured a solution where someone else does all the work. GitHub already has a validation system, usernames, logins, and a publicly editable “wiki”. MVP. No maintenance, no vetting, no development. GitHub already shows up in google so whoever searches for “hire an R programmer” will find you if you put your details there.

It’s actually unbelievable that we’ve had R-Bloggers as a gathering place for so long, but nowhere central to list who’s looking for work.

So I committed https://github.com/isomorphisms/hire-an-r-programmer/blob/gh-pages/README.md which is a markdown file you can add your information to, if you want to be found by recruiters who are looking for R programmers. Forking is a good design pattern for this purpose as well. Add whatever information you want, and if you think I’m missing some fields you can add those as well. Suggestions/comments also welcome below.




An insufficiently ugly temporary hack is permanent.
Benjamin Black (@b6n)

(Source: blog.b3k.us)




@bos31337 Running a startup (MailRank) on Haskell (por jasonofthel33t)

Even though this is an advanced talk, there’s still something here for business people who know very little about software but are interested in web startups.

Namely, at Minute 20 BOS ticks off the things that a web app needs to do, like:

  • load balancing requests,
  • proxying data off…
  • for his Haskell code to bang on…
  • in the cloud,
  • receive requests from a Windows desktop software written in C#
  • coördinate those with what he already had,
  • store the data (thus evaluate a database appropriate for their problem),
  • worry about server throughput,
  • connect (bind) his (main) Haskell code to the database, to the server, to the webapp,
  • evaluate server software,

This surveys the moving parts in an internet-based business.




A perlmonk asked for a “custom random number generator”. This is a non-maths person’s word for a probability distribution.

image

It was a slightly unusual case, but not hard. After I’d finished several easy steps, though, the final formula looked like it had been scrivened by a wizard:

image

Of course, I’m not a wizard; I’m not even an acolyte. The steps I took just involved (1) a certain viewpoint on probability distributions, and (2) puzzles that an 11-year-old could solve. 

This is how formulas in textbooks get to look so daunting.

 —skippable interlude— 

I guess I figured this out years ago, when I first saw the Black-Scholes-Merton formula in business school.

image

The BSM is just a continuous-time limit of “Did the stock go up or down in the last 5 minutes?” But the BSM is dressed up with such frightening language that it seems much more inscrutable than “A tree generated from two alternatives which are repeated”.

\frac{\partial V}{\partial t} + \frac{1}{2}\sigma^2 S^2 \frac{\partial^2 V}{\partial S^2} + rS\frac{\partial V}{\partial S} - rV = 0

For example in the Wikipedia article on BSM the subheads include: Greeks (), elliptic PDE’s, derivation, interpretation, criticism, extensions of the model, notation, assumptions, references. It’s 24 pagedowns long. From this pretence of sophistication follows:

I’ve seen it in biology, chemistry, and physics textbooks as well. A convoluted formula encodes the results of a simple model. Because of scientism the students commit it to memory as well as more derived results. Hopefully they come to find that it was not so complicated only a professors could understand it.

But I don’t think that’s common knowledge, so formulæ retain an impenetrable mysticism and the rituals of uncomprehending repetition continue.

 —back to the main idea— 

It needn’t be so enigmatic. I can demonstrate that by showing how the ugly beast above looks if you break it into steps. It’s simpler as several lines of code than as one formula.

Client Request

Anonymous Monk wanted a probability distribution like this:

image

with the median at x and equal probability masses between [x/y,x] and [x, x•y]

Drawrings

I’m going to take a Gaussian and map the endpoints to what the client wants.

image

The result will tend to the centre a “normal” amount of the time and yet will be squashed onto the domain the client wants.

Match up the Endpoints

I know that exp maps (−∞,0] onto (0,1]

To follow that, I need a transformation that will match (0,1) to (x/y, x). So 1 ⟼ x and 0 ⟼ x/y.

0 ⟼ x and 1 ⟼ xy

as 6 lines of Code

my $random = ...; #Gaussians, however you fry them up
if ($random <= 0) { 
$random = exp($random); #map (−∞,0) → (0,1)
$random =     ; #map (0,1) → (x, x•y)


}
else { #map (0, +∞) → (0,1)
$random = 1 − exp(−$random);  #map (0, +∞) → (0,1) ... which is the same problem as above except backwards
$random =     ; #map (0,1) → (x/y, x)

Lessons:

  1. use paper first, write code second
  2. draw a picture
  3. if necessary, break it into a simpler picture
  4. compose the answers to the parts
  5. code the pieces in separate lines

The equation at the top does decompose into the sequence of steps I just outlined. But even though it looks simple as a sequence of steps, the one-line formula is scary.













Oh, much less. The total memory was four kilobytes. And he did an amazing lot with that. Especially a biologist who was there at the time, called Nils Barricelli, did simulated evolution amazingly well with a memory of four kilobytes. He developed models of evolving creatures forming an ecology, and they showed punctuated equilibrium, exactly the way real species do. It was astonishing how much he could get out of that machine.
Freeman Dyson, via University of David




What does it mean to program in a functional style?  (por Brian Will)

  • functions can be passed—as arguments—to other functions
  • if, try, while return something
  • adhere to statelessness (no side effects, so you can see everything that a function does just looking in the one place)




Minute 10 — The point of this talk is how much “boilerplate” or standard lengthy expressions are necessary in Java to do, what’s essentially nothing: define a class whose members consist of three strings.

(Source: cufp.org)