Show More
@@ -83,11 +83,9 b' def Rconverter(Robj, dataframe=False):' | |||||
83 | rownames = ro.r('rownames') # with pandas, these could be used for the index |
|
83 | rownames = ro.r('rownames') # with pandas, these could be used for the index | |
84 | names = ro.r('names') |
|
84 | names = ro.r('names') | |
85 |
|
85 | |||
86 |
|
||||
87 | if dataframe: |
|
86 | if dataframe: | |
88 | as_data_frame = ro.r('as.data.frame') |
|
87 | as_data_frame = ro.r('as.data.frame') | |
89 | cols = colnames(Robj) |
|
88 | cols = colnames(Robj) | |
90 | rows = rownames(Robj) |
|
|||
91 | _names = names(Robj) |
|
89 | _names = names(Robj) | |
92 | if cols != ri.NULL: |
|
90 | if cols != ri.NULL: | |
93 | Robj = as_data_frame(Robj) |
|
91 | Robj = as_data_frame(Robj) | |
@@ -336,7 +334,9 b' class RMagics(Magics):' | |||||
336 |
|
334 | |||
337 | In line mode, this will evaluate an expression and convert the returned value to a Python object. |
|
335 | In line mode, this will evaluate an expression and convert the returned value to a Python object. | |
338 | The return value is determined by rpy2's behaviour of returning the result of evaluating the |
|
336 | The return value is determined by rpy2's behaviour of returning the result of evaluating the | |
339 | final line. Multiple R lines can be executed by joining them with semicolons:: |
|
337 | final line. | |
|
338 | ||||
|
339 | Multiple R lines can be executed by joining them with semicolons:: | |||
340 |
|
340 | |||
341 | In [9]: %R X=c(1,4,5,7); sd(X); mean(X) |
|
341 | In [9]: %R X=c(1,4,5,7); sd(X); mean(X) | |
342 | Out[9]: array([ 4.25]) |
|
342 | Out[9]: array([ 4.25]) | |
@@ -398,8 +398,11 b' class RMagics(Magics):' | |||||
398 | * If the final line results in a NULL value when evaluated |
|
398 | * If the final line results in a NULL value when evaluated | |
399 | by rpy2, then None is returned. |
|
399 | by rpy2, then None is returned. | |
400 |
|
400 | |||
401 | The --dataframe argument will return structured arrays |
|
401 | * No attempt is made to convert the final value to a structured array. | |
402 | from dataframes in R. This is useful for dataframes with |
|
402 | Use the --dataframe flag or %Rget to push / return a structured array. | |
|
403 | ||||
|
404 | The --dataframe argument will attempt to return structured arrays. | |||
|
405 | This is useful for dataframes with | |||
403 | mixed data types. Note also that for a data.frame, |
|
406 | mixed data types. Note also that for a data.frame, | |
404 | if it is returned as an ndarray, it is transposed:: |
|
407 | if it is returned as an ndarray, it is transposed:: | |
405 |
|
408 | |||
@@ -427,9 +430,8 b' class RMagics(Magics):' | |||||
427 | array([(1, 2.9, 'a'), (2, 3.5, 'b'), (3, 2.1, 'c'), (4, 5.0, 'e')], |
|
430 | array([(1, 2.9, 'a'), (2, 3.5, 'b'), (3, 2.1, 'c'), (4, 5.0, 'e')], | |
428 | dtype=[('x', '<i4'), ('y', '<f8'), ('z', '|S1')]) |
|
431 | dtype=[('x', '<i4'), ('y', '<f8'), ('z', '|S1')]) | |
429 |
|
432 | |||
430 |
The --dataframe argument first tries colnames, then |
|
433 | The --dataframe argument first tries colnames, then names. | |
431 |
If |
|
434 | If both are NULL, it returns an ndarray (i.e. unstructured):: | |
432 |
|
||||
433 |
|
435 | |||
434 | In [1]: %R mydata=c(4,6,8.3); NULL |
|
436 | In [1]: %R mydata=c(4,6,8.3); NULL | |
435 |
|
437 | |||
@@ -452,7 +454,6 b' class RMagics(Magics):' | |||||
452 | In [8]: mydata |
|
454 | In [8]: mydata | |
453 | Out[8]: array([ 4. , 6. , 8.3]) |
|
455 | Out[8]: array([ 4. , 6. , 8.3]) | |
454 |
|
456 | |||
455 |
|
||||
456 | ''' |
|
457 | ''' | |
457 |
|
458 | |||
458 | args = parse_argstring(self.R, line) |
|
459 | args = parse_argstring(self.R, line) |
General Comments 0
You need to be logged in to leave comments.
Login now