Created
December 11, 2015 18:37
-
-
Save jeffbaumes/471438c89782e99af815 to your computer and use it in GitHub Desktop.
Run R through Romanesco
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import romanesco | |
| simple = { | |
| "inputs": [], | |
| "outputs": [{"name": "output", "type": "number", "format": "number"}], | |
| "script": "output = 4", | |
| "mode": "r" | |
| } | |
| print romanesco.run(simple) | |
| tableio = { | |
| "inputs": [{"name": "input", "type": "table", "format": "r.dataframe"}], | |
| "outputs": [{"name": "output", "type": "table", "format": "r.dataframe"}], | |
| "script": "output = input", | |
| "mode": "r" | |
| } | |
| print romanesco.run( | |
| tableio, | |
| {'input': {'format': 'csv', 'data': 'a,b,c\n1,2,3'}}, | |
| {'output': {'format': 'objectlist'}}) | |
| columnadd = { | |
| "mode": "r", | |
| "name": "Add columns", | |
| "inputs": [ | |
| { | |
| "format": "r.dataframe", | |
| "name": "input", | |
| "type": "table" | |
| }, | |
| { | |
| "format": "text", | |
| "name": "columnOne", | |
| "type": "string" | |
| }, | |
| { | |
| "format": "text", | |
| "name": "columnTwo", | |
| "type": "string" | |
| }, | |
| { | |
| "format": "text", | |
| "name": "outputColumn", | |
| "type": "string" | |
| } | |
| ], | |
| "outputs": [ | |
| { | |
| "format": "r.dataframe", | |
| "name": "output", | |
| "type": "table" | |
| } | |
| ], | |
| "script": """ | |
| # Add some columns | |
| output = input | |
| output[,outputColumn] = input[,columnOne] + input[,columnTwo] | |
| """ | |
| } | |
| print romanesco.run( | |
| columnadd, | |
| { | |
| 'input': {'format': 'csv', 'data': 'a,b,c\n1,2,3\n4,5,6'}, | |
| 'columnOne': {'format': 'text', 'data': 'a'}, | |
| 'columnTwo': {'format': 'text', 'data': 'c'}, | |
| 'outputColumn': {'format': 'text', 'data': 'x'} | |
| }, | |
| {'output': {'format': 'csv'}} | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment