private void checkInit(final int flags, final RService r, final IProgressMonitor monitor) throws CoreException { if ((flags & INITIAL) == INITIAL || fRPlatform == null) { checkRVersion(r.getPlatform()); final IREnvConfiguration config = fREnv.getConfig(); if (config != null && config.isRemote()) { fRLibGroups = REnvLibGroups.loadFromR(r, monitor); } } }
private void runApplyRepo( final ISelectedRepos repos, final RService r, final IProgressMonitor monitor) throws CoreException { monitor.subTask("Setting repository configuration..."); try { if (repos.getBioCMirror() != null) { final FunctionCall call = r.createFunctionCall("options"); call.addChar("BioC_mirror", repos.getBioCMirror().getURL()); call.evalVoid(monitor); } { final List<RRepo> selectedRepos = (List<RRepo>) repos.getRepos(); final String[] ids = new String[selectedRepos.size()]; final String[] urls = new String[selectedRepos.size()]; for (int i = 0; i < urls.length; i++) { final RRepo repo = selectedRepos.get(i); ids[i] = repo.getId(); urls[i] = repo.getURL(); } final RVector<RCharacterStore> data = new RVectorImpl<RCharacterStore>( new RCharacterDataImpl(urls), RObject.CLASSNAME_CHARACTER, ids); final FunctionCall call = r.createFunctionCall("options"); call.add("repos", data); call.evalVoid(monitor); } } catch (final CoreException e) { throw new CoreException( new Status( IStatus.ERROR, RCore.PLUGIN_ID, "An error occurred when setting repository configuration in R.", e)); } }
private ISelectedRepos runLoadRepos(final RService r, final IProgressMonitor monitor) throws CoreException { try { String bioCVersion; { final RObject data = r.evalData("as.character(tools:::.BioC_version_associated_with_R_version)", monitor); bioCVersion = RDataUtil.checkSingleCharValue(data); } final boolean loadRMirrors = ((fRequireLoad & (REQUIRE_CRAN | REQUIRE_BIOC)) != 0); final boolean loadRRepos = ((fRequireLoad & (REQUIRE_REPOS)) != 0); List<RRepo> rCRAN = null; List<RRepo> rBioC = null; String selectedCRAN = null; RRepo rCRANByCountry = null; String selectedBioC = null; if (loadRMirrors) { monitor.subTask("Fetching available mirrors..."); final String region = Locale.getDefault().getCountry().toLowerCase(); { final RObject data = r.evalData( "getCRANmirrors()[c('Name', 'URL', 'CountryCode')]", monitor); // $NON-NLS-1$ final RDataFrame df = RDataUtil.checkRDataFrame(data); final RCharacterStore names = RDataUtil.checkRCharVector(df.get("Name")).getData(); // $NON-NLS-1$ final RCharacterStore urls = RDataUtil.checkRCharVector(df.get("URL")).getData(); // $NON-NLS-1$ final RCharacterStore regions = RDataUtil.checkRCharVector(df.get("CountryCode")).getData(); // $NON-NLS-1$ final int l = RDataUtil.checkIntLength(names); rCRAN = new ArrayList<>(l); for (int i = 0; i < l; i++) { final String url = Util.checkURL(urls.getChar(i)); if (!url.isEmpty()) { final RRepo repo = new RRepo(RRepo.R_PREFIX + url, names.getChar(i), url, null); rCRAN.add(repo); if (rCRANByCountry == null && !region.isEmpty() && region.equals(regions.getChar(i))) { rCRANByCountry = repo; } } } } { final String[][] fix = new String[][] { {"Seattle (USA)", "http://www.bioconductor.org"}, {"Bethesda (USA)", "http://watson.nci.nih.gov/bioc_mirror"}, {"Dortmund (Germany)", "http://bioconductor.statistik.tu-dortmund.de"}, {"Bergen (Norway)", "http://bioconductor.uib.no"}, {"Cambridge (UK)", "http://mirrors.ebi.ac.uk/bioconductor"} }; rBioC = new ArrayList<>(fix.length); for (int i = 0; i < fix.length; i++) { final String url = Util.checkURL(fix[i][1]); if (!url.isEmpty()) { rBioC.add(new RRepo(RRepo.R_PREFIX + url, fix[i][0], url, null)); } } } } List<RRepo> rrepos = null; List<RRepo> selected = null; if (loadRRepos) { monitor.subTask("Fetching available repositories..."); { final RObject data = r.evalData("options('repos')[[1L]]", monitor); // $NON-NLS-1$ if (data.getRObjectType() != RObject.TYPE_NULL) { final RCharacterStore urls = RDataUtil.checkRCharVector(data).getData(); final RStore ids = ((RVector<?>) data).getNames(); final int l = RDataUtil.checkIntLength(urls); selected = new ArrayList<>(l); for (int i = 0; i < l; i++) { final String id = (ids != null) ? ids.getChar(i) : null; final String url = urls.getChar(i); final RRepo repo = Util.createRepoFromR(id, null, url); if (repo != null) { selected.add(repo); } } } else { selected = new ArrayList<>(4); } } final RObject data = r.evalData( "local({" + //$NON-NLS-1$ "p <- file.path(Sys.getenv('HOME'), '.R', 'repositories')\n" + //$NON-NLS-1$ "if (!file.exists(p)) p <- file.path(R.home('etc'), 'repositories')\n" + //$NON-NLS-1$ "r <- utils::read.delim(p, header = TRUE, comment.char = '#', colClasses = c(rep.int('character', 3L), rep.int('logical', 4L)))\n" + //$NON-NLS-1$ "r[c(names(r)[1L], 'URL', 'default')]\n" + //$NON-NLS-1$ "})", monitor); //$NON-NLS-1$ final RDataFrame df = RDataUtil.checkRDataFrame(data); final RStore ids = df.getRowNames(); final RCharacterStore labels = RDataUtil.checkRCharVector(df.get(0)).getData(); final RCharacterStore urls = RDataUtil.checkRCharVector(df.get("URL")).getData(); // $NON-NLS-1$ final RLogicalStore isDefault = (selected.isEmpty()) ? RDataUtil.checkRLogiVector(df.get("default")).getData() : null; //$NON-NLS-1$ { final int l = RDataUtil.checkIntLength(labels); rrepos = new ArrayList<>(l + 4); for (int i = 0; i < l; i++) { final String id = (ids != null) ? ids.getChar(i) : null; final String url = urls.getChar(i); final RRepo repo = Util.createRepoFromR(id, labels.getChar(i), url); if (repo != null) { rrepos.add(repo); if (isDefault != null && isDefault.getLogi(i)) { selected.add(repo); } } } } for (int i = 0; i < selected.size(); i++) { final RRepo repo = selected.get(i); RRepo rrepo = null; if (!repo.getURL().isEmpty()) { rrepo = RPkgUtil.getRepoByURL(rrepos, repo.getURL()); } if (rrepo != null) { selected.set(i, rrepo); continue; } if (!repo.getId().isEmpty()) { final int j = rrepos.indexOf(repo); // by id if (j >= 0) { rrepo = rrepos.get(j); if (!RVarRepo.hasVars(rrepo.getURL())) { rrepo.setURL(repo.getURL()); } selected.set(i, rrepo); continue; } } repo.setName(RRepo.hintName(repo)); continue; } } if (loadRMirrors) { if (loadRRepos) { final RRepo repo = RPkgUtil.getRepoById(rrepos, RRepo.CRAN_ID); if (repo != null && !repo.getURL().isEmpty() && !RVarRepo.hasVars(repo.getURL())) { selectedCRAN = repo.getURL(); } } else { final RObject data = r.evalData("options('repos')[[1L]]['CRAN']", monitor); // $NON-NLS-1$ if (data.getRObjectType() != RObject.TYPE_NULL) { final String url = Util.checkURL(RDataUtil.checkSingleChar(data)); if (!url.isEmpty() && !RVarRepo.hasVars(url)) { selectedCRAN = url; } } } { final RObject data = r.evalData("options('BioC_mirror')[[1L]]", monitor); // $NON-NLS-1$ if (data.getRObjectType() != RObject.TYPE_NULL) { selectedBioC = RDataUtil.checkSingleChar(data); } } } getWriteLock().lock(); try { fBioCVersion = bioCVersion; if (loadRMirrors) { fRequireLoad &= ~(REQUIRE_CRAN | REQUIRE_BIOC); fRCRAN = rCRAN; fRCRANByCountry = rCRANByCountry; fSelectedCRANInR = selectedCRAN; fRBioC = rBioC; fSelectedBioCInR = selectedBioC; fMirrorsStamp = fRTaskEvent.fStamp; checkMirrors(fRTaskEvent); } if (loadRRepos) { fRequireLoad &= ~(REQUIRE_REPOS); fRRepos = rrepos; fSelectedReposInR = selected; checkRepos(fRTaskEvent); } fFirstTime = false; if (getReposStatus(fSelectedRepos, fSelectedRepos, fRequireConfirm).isOK()) { return fSelectedRepos; } return null; } finally { getWriteLock().unlock(); } } catch (final Exception e) { throw new CoreException( new Status( IStatus.ERROR, RCore.PLUGIN_ID, 0, "An error occurred when loading data for package manager.", e)); } }
private void checkInstalled( final FullRPkgSet pkgs, final RService r, final IProgressMonitor monitor) throws CoreException { RVector<RNumericStore> libs = null; boolean[] update = null; try { libs = RDataUtil.checkRNumVector(r.evalData("rj:::.renv.checkLibs()", monitor)); // $NON-NLS-1$ final int l = RDataUtil.checkIntLength(libs.getData()); ITER_LIBS: for (int idxLib = 0; idxLib < l; idxLib++) { final String libPath = libs.getNames().getChar(idxLib); if (fLibs != null) { final int idx = (int) fLibs.getNames().indexOf(libPath); if (idx >= 0) { if (fLibs.getData().getNum(idx) == libs.getData().getNum(idxLib)) { continue ITER_LIBS; } } } if (update == null) { update = new boolean[l]; } update[idxLib] = true; } fLibs = libs; } catch (final UnexpectedRDataException | CoreException e) { throw new CoreException( new Status( IStatus.ERROR, RCore.PLUGIN_ID, "An error occurred when checking for changed R libraries.", e)); } if (update != null || pkgs != null) { if (fRTaskEvent == null) { fRTaskEvent = new Change(fREnv); } if (fRTaskEvent.fOldPkgs == null) { fRTaskEvent.fOldPkgs = getRPkgSet(); } if (fPkgsExt != null || pkgs != null) { final FullRPkgSet newPkgs = (pkgs != null) ? pkgs : fPkgsExt.cloneAvailable(); fRTaskEvent.fNewPkgs = newPkgs; fRLibPaths = RLibPaths.create(getRLibGroups(), libs, r, monitor); fPkgScanner.updateInstFull(fRLibPaths, update, newPkgs, fRTaskEvent, r, monitor); } else { final RPkgSet newPkgs = new RPkgSet((int) libs.getLength()); fRTaskEvent.fNewPkgs = newPkgs; fRLibPaths = RLibPaths.createLight(getRLibGroups(), libs); fPkgScanner.updateInstLight(fRLibPaths, update, newPkgs, fRTaskEvent, r, monitor); } if (fRTaskEvent.fInstalledPkgs != null && fRTaskEvent.fInstalledPkgs.names.isEmpty()) { fRTaskEvent.fInstalledPkgs = null; } if (pkgs == null) { setPkgs(); } if (fRTaskEvent.fInstalledPkgs != null && fDB != null) { fDB.updatePkgs(fRTaskEvent); } } }