From 14aacee65f2521d087b3e5cfbf62b9ca82f614fc Mon Sep 17 00:00:00 2001 From: Donald Curtis Date: Sat, 24 Nov 2012 19:56:04 -0600 Subject: [PATCH] Fix units / res args for *png* plotting device. Update the `units` argument so that it accepts values from ["px", "in", "cm", "mm"]. The `res` argument was added for the cases where `units` is specified and is not default (px). A default value of 72 is provided by rmagic in the case that `units` is not "px" but `res` is not specified. --- IPython/extensions/rmagic.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/IPython/extensions/rmagic.py b/IPython/extensions/rmagic.py index 1fdfa95e0e2..b8fbe586b7c 100644 --- a/IPython/extensions/rmagic.py +++ b/IPython/extensions/rmagic.py @@ -323,9 +323,13 @@ def Rget(self, line): 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.' @@ -507,7 +511,12 @@ def R(self, line, cell=None, local_ns=None): val = self.shell.user_ns[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