code: def _to_r(o, as_data=False, level=0):
      
      if o is None:
          return "NA"
      if isinstance(o, basestring):
          return o
      if hasattr(o, "r"):
          # bridge to @property r on GGStatement(s)
          return o.r
      elif isinstance(o, bool):
          return "TRUE" if o else "FALSE"
      elif isinstance(o, (list, tuple)):
          inner = ",".join([_to_r(x, True, level+1) for x in o])
          return "c({})".format(inner) if as_data else inner
      elif isinstance(o, dict):
          inner = ",".join(["{}={}".format(k, _to_r(v, True, level+1))
                           for k, v in sorted(o.iteritems(), key=lambda x: x[0])])
          return "list({})".format(inner) if as_data else inner
      return str(o)
docs: Helper function to convert python data structures to R equivalents
  
      TODO: a single model for transforming to r to handle
      * function args
      * lists as function args