
import click
from rpy2.robjects import DataFrame, Formula, globalenv
from rpy2.robjects.packages import importr


grdevices = importr('grDevices')
lattice = importr('lattice')
rprint = globalenv.get("print")


def xyplot(formula, data, **kwargs):
    if not isinstance(formula, Formula):
        formula = Formula(formula)
    plot = lattice.xyplot(
        formula, data, **kwargs)
    rprint(plot)


@click.command()
def main():
    import numpy as np
    from rpy2.robjects import numpy2ri
    numpy2ri.activate()

    x = np.random.random_integers(0, 100, 100)
    x.sort()
    y = np.square(x)
    xyplot('y ~ x', DataFrame({'x': x, 'y': y}))
    raw_input('Hit enter to exit.')
    grdevices.dev_off()


if __name__ == '__main__':
    main()


import click
from rpy2.robjects import DataFrame, Formula, globalenv
from rpy2.robjects.packages import importr


grdevices = importr('grDevices')
lattice = importr('lattice')
rprint = globalenv.get("print")


def xyplot(formula, data, **kwargs):
    """Call lattice's `xyplot` with the given `formula` and `data`.

    You can supply `formula` as a string or rpy2 `Formula`.

    You can supply `data` as a dict or rpy2 `DataFrame`.

    """

    if not isinstance(data, DataFrame):
        data = DataFrame(data)
    if not isinstance(formula, Formula):
        formula = Formula(formula)
    plot = lattice.xyplot(
        formula, data, **kwargs)
    rprint(plot)


@click.command()
def main():
    import numpy as np
    from rpy2.robjects import numpy2ri
    numpy2ri.activate()

    x = np.random.random_integers(0, 100, 100)
    x.sort()
    y = np.square(x)
    xyplot('y ~ x', DataFrame({'x': x, 'y': y}))
    raw_input('Hit enter to exit.')
    grdevices.dev_off()


if __name__ == '__main__':
    main()

Document the xyplot function and support data dict
Document the xyplot function and support data dict

  
  import click
  from rpy2.robjects import DataFrame, Formula, globalenv
  from rpy2.robjects.packages import importr
  
  
  grdevices = importr('grDevices')
  lattice = importr('lattice')
  rprint = globalenv.get("print")
  
  
  def xyplot(formula, data, **kwargs):
+     """Call lattice's `xyplot` with the given `formula` and `data`.
+ 
+     You can supply `formula` as a string or rpy2 `Formula`.
+ 
+     You can supply `data` as a dict or rpy2 `DataFrame`.
+ 
+     """
+ 
+     if not isinstance(data, DataFrame):
+         data = DataFrame(data)
      if not isinstance(formula, Formula):
          formula = Formula(formula)
      plot = lattice.xyplot(
          formula, data, **kwargs)
      rprint(plot)
  
  
  @click.command()
  def main():
      import numpy as np
      from rpy2.robjects import numpy2ri
      numpy2ri.activate()
  
      x = np.random.random_integers(0, 100, 100)
      x.sort()
      y = np.square(x)
      xyplot('y ~ x', DataFrame({'x': x, 'y': y}))
      raw_input('Hit enter to exit.')
      grdevices.dev_off()
  
  
  if __name__ == '__main__':
      main()
  
Document the xyplot function and support data dict
## Code Before:

import click
from rpy2.robjects import DataFrame, Formula, globalenv
from rpy2.robjects.packages import importr


grdevices = importr('grDevices')
lattice = importr('lattice')
rprint = globalenv.get("print")


def xyplot(formula, data, **kwargs):
    if not isinstance(formula, Formula):
        formula = Formula(formula)
    plot = lattice.xyplot(
        formula, data, **kwargs)
    rprint(plot)


@click.command()
def main():
    import numpy as np
    from rpy2.robjects import numpy2ri
    numpy2ri.activate()

    x = np.random.random_integers(0, 100, 100)
    x.sort()
    y = np.square(x)
    xyplot('y ~ x', DataFrame({'x': x, 'y': y}))
    raw_input('Hit enter to exit.')
    grdevices.dev_off()


if __name__ == '__main__':
    main()

## Instruction:
Document the xyplot function and support data dict
## Code After:

import click
from rpy2.robjects import DataFrame, Formula, globalenv
from rpy2.robjects.packages import importr


grdevices = importr('grDevices')
lattice = importr('lattice')
rprint = globalenv.get("print")


def xyplot(formula, data, **kwargs):
    """Call lattice's `xyplot` with the given `formula` and `data`.

    You can supply `formula` as a string or rpy2 `Formula`.

    You can supply `data` as a dict or rpy2 `DataFrame`.

    """

    if not isinstance(data, DataFrame):
        data = DataFrame(data)
    if not isinstance(formula, Formula):
        formula = Formula(formula)
    plot = lattice.xyplot(
        formula, data, **kwargs)
    rprint(plot)


@click.command()
def main():
    import numpy as np
    from rpy2.robjects import numpy2ri
    numpy2ri.activate()

    x = np.random.random_integers(0, 100, 100)
    x.sort()
    y = np.square(x)
    xyplot('y ~ x', DataFrame({'x': x, 'y': y}))
    raw_input('Hit enter to exit.')
    grdevices.dev_off()


if __name__ == '__main__':
    main()
