

def execute_r(command='Rcmd', *args):
    if r_install_valid():
        valid_commands = ['R', 'Rcmd', 'Rscript']
        if (command not in valid_commands):
            arcpy.AddError("Invalid R command, '{}.exe'.".format(command))
            return
        rcommand_exe = '{}.exe'.format(command)
        rcommand_path = os.path.join(r_install_path, 'bin', platform(), rcommand_exe)
        rcommand_dir = os.path.dirname(rcommand_path)
        sys_path = os.getenv('PATH')
        if os.path.exists(rcommand_dir):
            os.putenv('PATH', ';'.join([rcommand_dir, sys_path]))
        if r_command_valid(rcommand_path):
            command_parts = ([rcommand_exe] + list(args))
            arcpy.AddMessage(subprocess.list2cmdline(command_parts))
            if (command is 'Rscript'):
                script_base = os.path.dirname(os.path.realpath(__file__))
                script_path = os.path.join(script_base, args[0])
                if (not os.path.exists(sys_path)):
                    arcpy.AddError("Couldn't locate requested script, '{}'.".format(script_path))
                    return
                else:
                    command_parts[1] = script_path
            process = subprocess.Popen(command_parts, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, cwd=rcommand_dir)
            while (process.poll() is None):
                stdout_msg = process.stdout.readline().strip()
                if stdout_msg:
                    arcpy.AddMessage(stdout_msg)
                stderr_msg = process.stderr.readline().strip()
                if stderr_msg:
                    arcpy.AddWarning(stderr_msg)
            if (process.returncode == 0):
                pass
            else:
                arcpy.AddWarning('R command returned non-zero exit status.')
            return process.returncode

dataset/ETHPy150Open R-ArcGIS/r-bridge-install/rtools/bootstrap_r.py execute_r/VarMisuse@221/329 `script_path`->`sys_path`