From e3f3a0c9ac479bced16fb6eebb1912d663bdbd5e 2013-01-08 00:35:57 From: Thomas Kluyver Date: 2013-01-08 00:35:57 Subject: [PATCH] Merge branch 'fix-rmagic' --- diff --git a/IPython/extensions/rmagic.py b/IPython/extensions/rmagic.py index 21aeeab..753e0db 100644 --- a/IPython/extensions/rmagic.py +++ b/IPython/extensions/rmagic.py @@ -337,10 +337,14 @@ class RMagics(Magics): help='Convert these objects to data.frames and return as structured arrays.' ) @argument( - '-u', '--units', type=int, + '-u', '--units', type=unicode, choices=["px", "in", "cm", "mm"], help='Units of png plotting device sent as an argument to *png* in R. One of ["px", "in", "cm", "mm"].' ) @argument( + '-r', '--res', type=int, + help='Resolution of png plotting device sent as an argument to *png* in R. Defaults to 72 if *units* is one of ["in", "cm", "mm"].' + ) + @argument( '-p', '--pointsize', type=int, help='Pointsize of png plotting device sent as an argument to *png* in R.' ) @@ -524,7 +528,12 @@ class RMagics(Magics): raise NameError("name '%s' is not defined" % input) self.r.assign(input, self.pyconverter(val)) - png_argdict = dict([(n, getattr(args, n)) for n in ['units', 'height', 'width', 'bg', 'pointsize']]) + if getattr(args, 'units') is not None: + if args.units != "px" and getattr(args, 'res') is None: + args.res = 72 + args.units = '"%s"' % args.units + + png_argdict = dict([(n, getattr(args, n)) for n in ['units', 'res', 'height', 'width', 'bg', 'pointsize']]) png_args = ','.join(['%s=%s' % (o,v) for o, v in png_argdict.items() if v is not None]) # execute the R code in a temporary directory diff --git a/IPython/extensions/tests/test_rmagic.py b/IPython/extensions/tests/test_rmagic.py index 4e128a8..43be445 100644 --- a/IPython/extensions/tests/test_rmagic.py +++ b/IPython/extensions/tests/test_rmagic.py @@ -71,7 +71,7 @@ def test_cell_magic(): r = resid(a) xc = coef(a) ''' - ip.run_cell_magic('R', '-i x,y -o r,xc a=lm(y~x)', snippet) + ip.run_cell_magic('R', '-i x,y -o r,xc -w 150 -u mm a=lm(y~x)', snippet) np.testing.assert_almost_equal(ip.user_ns['xc'], [3.2, 0.9]) np.testing.assert_almost_equal(ip.user_ns['r'], np.array([-0.2, 0.9, -1. , 0.1, 0.2]))