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)); } }
@Override public boolean allEqual(final RStore<?> other) { return (INTEGER == other.getStoreType() && -1 == other.getLength()); }