code: def rcollect(expr, *vars):
      """
      Recursively collect sums in an expression.
  
      Examples
      ========
  
      >>> from sympy.simplify import rcollect
      >>> from sympy.abc import x, y
  
      >>> expr = (x**2*y + x*y + x + y)/(x + y)
  
      >>> rcollect(expr, y)
      (x + y*(x**2 + x + 1))/(x + y)
  
      See Also
      ========
  
      collect, collect_const, collect_sqrt
      """
      if expr.is_Atom or not expr.has(*vars):
          return expr
      else:
          expr = expr.__class__(
              *[rcollect(arg, *vars) for arg in expr.args]
          )
  
          if expr.is_Add:
              return collect(expr, vars)
          else:
              return expr
  
imports: from collections import defaultdict
  from sympy.core import sympify, S, Mul, Derivative, Pow
  from sympy.core.add import _unevaluated_Add, Add
  from sympy.core.assumptions import assumptions
  from sympy.core.exprtools import Factors, gcd_terms
  from sympy.core.function import _mexpand, expand_mul, expand_power_base
  from sympy.core.mul import _keep_coeff, _unevaluated_Mul, _mulsort
  from sympy.core.numbers import Rational, zoo, nan
  from sympy.core.parameters import global_parameters
  from sympy.core.sorting import ordered, default_sort_key
  from sympy.core.symbol import Dummy, Wild, symbols
  from sympy.functions import exp, sqrt, log
  from sympy.functions.elementary.complexes import Abs
  from sympy.polys import gcd
  from sympy.simplify.sqrtdenest import sqrtdenest
  from sympy.utilities.iterables import iterable, sift
label_desc: Use image node_id 2 for calling a global function with example usage: rcollect(expr) and returns: expr, collect, expr