예제 #1
0
def ensure_R_setup():
    from rpy2 import situation
    try:
        if not situation.get_r_home(
        ) or not situation.r_version_from_subprocess():
            raise MissingR()

    except MissingR as e:
        raise e
예제 #2
0
파일: setup.py 프로젝트: Trixter9994/lazero
def get_r_c_extension_status():
    r_home = situation.get_r_home()
    if r_home is None:
        return COMPILATION_STATUS.NO_R
    c_ext = situation.CExtensionOptions()
    c_ext.add_lib(*situation.get_r_flags(r_home, '--ldflags'))
    c_ext.add_include(*situation.get_r_flags(r_home, '--cppflags'))
    status = get_c_extension_status(libraries=c_ext.libraries,
                                    include_dirs=c_ext.include_dirs,
                                    library_dirs=c_ext.library_dirs)
    return status
예제 #3
0
def get_r_c_extension_status():
    r_home = situation.get_r_home()
    if r_home is None:
        print('There is no R_HOME and the R executable cannot be found.')
        sys.exit(1)
    c_ext = situation.CExtensionOptions()
    c_ext.add_lib(*situation.get_r_flags(r_home, '--ldflags'))
    c_ext.add_include(*situation.get_r_flags(r_home, '--cppflags'))
    status = get_c_extension_status(libraries=c_ext.libraries,
                                    include_dirs=c_ext.include_dirs,
                                    library_dirs=c_ext.library_dirs)
    return status
예제 #4
0
def get_r_c_extension_status():
    r_home = situation.get_r_home()
    if r_home is None:
        return COMPILATION_STATUS.NO_R
    c_ext = situation.CExtensionOptions()
    try:
        c_ext.add_lib(*situation.get_r_flags(r_home, '--ldflags'))
        c_ext.add_include(*situation.get_r_flags(r_home, '--cppflags'))
    except subprocess.CalledProcessError as cpe:
        warnings.warn(str(cpe))
        return COMPILATION_STATUS.RFLAGS_ERROR
    status = get_c_extension_status(libraries=c_ext.libraries,
                                    include_dirs=c_ext.include_dirs,
                                    library_dirs=c_ext.library_dirs)
    return status
예제 #5
0
def test_import_rpy2():
    import rpy2
    from rpy2 import situation
    assert LooseVersion(rpy2.__version__) >= LooseVersion(
        rlibs.RPY2_MIN_VERSION)
    assert situation.get_r_home() is not None
예제 #6
0
    Add directories containing R DLLs to the PATH environment variable.

    """
    import ctypes
    r_arch = ('i386', 'x64')[sys.maxsize > 2**32]
    r_mod = os.path.join(r_home, 'modules', r_arch)
    r_bin = os.path.join(r_home, 'bin', r_arch)
    r_dll = os.path.join(r_bin, 'R.dll')
    if not os.path.exists(r_dll):
        raise RuntimeError("Unable to locate R.dll at %s" % r_dll)
    if r_bin not in os.environ.get('PATH'):
        os.environ['PATH'] = ';'.join((os.environ.get('PATH'), r_bin, r_mod))
    ctypes.CDLL(r_dll)


R_HOME = get_r_home()

if not R_HOME:
    raise RuntimeError("""The R home directory could not be determined.

    Try to install R <https://www.r-project.org/>,
    set the R_HOME environment variable to the R home directory, or
    add the directory of the R interpreter to the PATH environment variable.
    """)

if not os.environ.get("R_HOME"):
    os.environ['R_HOME'] = R_HOME

if sys.platform == 'win32':
    _load_r_dll(R_HOME)