Skip to content

Commit

Permalink
Fix units / res args for *png* plotting device.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Donald Curtis committed Nov 25, 2012
1 parent c161745 commit 14aacee
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions IPython/extensions/rmagic.py
Expand Up @@ -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.'
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 14aacee

Please sign in to comment.