def initr_checkenv() -> typing.Union[int, None]: # Force the internal initialization flag if there is an environment # variable that indicates that R was alreay initialized in the current # process. status = None with openrlib.rlock: if embedded.is_r_externally_initialized(): embedded.setinitialized() else: status = embedded._initr() embedded.set_python_process_info() _rinterface._register_external_symbols() _post_initr_setup() return status
def _initr_win32( interactive: bool = True, _want_setcallbacks: bool = True, _c_stack_limit: int = _DEFAULT_C_STACK_LIMIT ) -> typing.Optional[int]: with openrlib.rlock: if embedded.isinitialized(): return None options_c = [ffi.new('char[]', o.encode('ASCII')) for o in embedded._options] n_options = len(options_c) n_options_c = ffi.cast('int', n_options) status = openrlib.rlib.Rf_initEmbeddedR(n_options_c, options_c) embedded.setinitialized() embedded.rstart = ffi.new('Rstart') rstart = embedded.rstart rstart.rhome = openrlib.rlib.get_R_HOME() rstart.home = openrlib.rlib.getRUser() rstart.CharacterMode = openrlib.rlib.LinkDLL if _want_setcallbacks: rstart.ReadConsole = callbacks._consoleread rstart.WriteConsoleEx = callbacks._consolewrite_ex rstart.CallBack = callbacks._callback rstart.ShowMessage = callbacks._showmessage rstart.YesNoCancel = callbacks._yesnocancel rstart.Busy = callbacks._busy rstart.R_Quiet = True rstart.R_Interactive = interactive rstart.RestoreAction = openrlib.rlib.SA_RESTORE rstart.SaveAction = openrlib.rlib.SA_NOSAVE rstart.vsize = ffi.cast('size_t', _DEFAULT_VSIZE) rstart.nsize = ffi.cast('size_t', _DEFAULT_NSIZE) rstart.max_vsize = ffi.cast('size_t', _DEFAULT_MAX_VSIZE) rstart.max_nsize = ffi.cast('size_t', _DEFAULT_MAX_NSIZE) rstart.ppsize = ffi.cast('size_t', _DEFAULT_PPSIZE) openrlib.rlib.R_SetParams(rstart) # TODO: still needed ? openrlib.rlib.R_CStackLimit = ffi.cast('uintptr_t', _c_stack_limit) return status