code: def build_rpackage(path: str) -> str:
      def find_tarball() -> str:
          found = []
          for root, subdir, files in os.walk("."):
              for f in files:
                  if f.endswith(".tar.gz") and f.startswith("xgboost"):
                      found.append(os.path.join(root, f))
          if not found:
              raise ValueError("Failed to find output tar ball.")
          if len(found) > 1:
              raise ValueError("Found more than one packages:", found)
          return found[0]
  
      env = os.environ.copy()
      print("Ncpus:", f"{os.cpu_count()}")
      env.update({"MAKEFLAGS": f"-j{os.cpu_count()}"})
      subprocess.check_call([R, "CMD", "build", path], env=env)
  
      tarball = find_tarball()
      return tarball
  
file_path: xgboost/tests/ci_build/test_r_package.py
imports: import argparse
  import os
  import shutil
  import subprocess
  from io import StringIO
  from pathlib import Path
  from platform import system
  from test_utils import R_PACKAGE, ROOT, DirectoryExcursion, cd, print_time, record_time
label_desc: Use image node_id 3 for calling a global function with example usage: build_rpackage(path) and returns: tarball, found