Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for `units` argument. Adds a `res` argument. #2617

Merged
merged 1 commit into from

2 participants

@milkypostman

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.

@milkypostman milkypostman 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.
14aacee
@milkypostman

This is a fix for #2615

@takluyver
Owner

Thanks, that looks promising. Have you tested the various different options?

I'll let someone more familiar with this code check it as well.

@milkypostman

I've tested this with units in and using different res values. I was wondering if there is some test code somewhere I should write?

@takluyver
Owner
@takluyver takluyver merged commit 14aacee into ipython:master

1 check passed

Details default The Travis build passed
@takluyver
Owner

Thanks again. I added a bit to the test and merged this.

@milkypostman
@takluyver
Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 25, 2012
  1. @milkypostman

    Fix units / res args for *png* plotting device.

    milkypostman authored
    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.
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 2 deletions.
  1. +11 −2 IPython/extensions/rmagic.py
View
13 IPython/extensions/rmagic.py
@@ -323,10 +323,14 @@ 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
Something went wrong with that request. Please try again.