Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Thursday, February 20, 2014

How to Install Shiny Server on OSX

I want to set up the shiny-server to run on an iMac at work so that we can run multiple R-apps over the intranet. According to the docs for Shiny server, OSX is not supported yet (version 1.1.0) so we are going to build it from source and hope for the best!

Instructions for building from source are here. We follow them pretty closely but there are a few gotchas.

The full HowTo is on our GitHub Wiki, here

Thursday, July 25, 2013

How to subset RPy2 dataframe

This example demonstrates how to create subsets of RPy2 data frames using single or multiple criteria. I also wanted to test if using Github Gist is a better way the display code snippets on this blog than using Bloggers formatting tools.

And linked gist is here

Monday, April 30, 2012

Convert Postgres column from text to numeric type

ALTER TABLE foo ALTER COLUMN col TYPE NUMERIC USING col::numeric

You can use this with data in the table.  All data must be convertable (no alpha chars). You can also specify numeric formatting here if you like.

Tuesday, November 9, 2010

How do you split a list into evenly sized chunks?

Answer was originally posted by Ned Batchelder on StackOverflow

Q: How do I split a list of arbitrary length into an equal number of smaller pieces that I can perform operations on?

A: Create a generator

Note the pprint library passes input directly through to stdin, as opposed to print.  Good thing to remember for future.


def chunks(l, n):
    """ Yield successive n-sized chunks from l.
    """
    for i in xrange(0, len(l), n):
        yield l[i:i+n]
import pprint
pprint.pprint(list(chunks(range(75), 10)))
[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
 [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
 [20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
 [30, 31, 32, 33, 34, 35, 36, 37, 38, 39],
 [40, 41, 42, 43, 44, 45, 46, 47, 48, 49],
 [50, 51, 52, 53, 54, 55, 56, 57, 58, 59],
 [60, 61, 62, 63, 64, 65, 66, 67, 68, 69],
 [70, 71, 72, 73, 74]]