old_contents: #! /usr/bin/env python2.7
  """Avoid some boilerplate rpy2 usage code with helpers.
  
  Mostly I wrote this so that I can use xyplot without having
  to remember a lot of details.
  
  """
  
  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()
  
new_contents: #! /usr/bin/env python2.7
  """Avoid some boilerplate rpy2 usage code with helpers.
  
  Mostly I wrote this so that I can use xyplot without having
  to remember a lot of details.
  
  """
  
  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()
  
subject: Document the xyplot function and support data dict