Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8016307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:30:15+00:00 2026-06-04T20:30:15+00:00

Is there a way to detect the closest R repository? This doesn’t have to

  • 0

Is there a way to detect the closest R repository? This doesn’t have to be perfect just reasonably close.

I’ll discuss the big picture as there may be a better way of going about what I’m doing. I’m writing a package that uses available.packages().

This throws up an error when I check the package saying:

Error in contrib.url(getOption("repos"), type):
  trying to use CRAN without setting a mirror.
Calls: p_cran -> available.packages -> contrib.url
Execution is halted

My thoughts are to set the mirror temporary using something like:

x <- getOption("repos")
#SOME HOW TEST IF x IS NOT SET BUT NOT SURE HOW
if (is.not.set(x)){
    y <- get.local.mirror.function()
    options(repos=structure(c(CRAN=y)))
    on.exit(options(repos=structure(c(CRAN=x))))
}

So I guess I have two problems to overcome if this route is reasonable:

  1. Determine if the repos has been set
  2. Find closest or some default to put in as the repos

Thank you in advance for help figuring this out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:30:16+00:00Added an answer on June 4, 2026 at 8:30 pm

    The tricky part of this problem isn’t getting the locations of the R repositories – it should be pretty easy to keep a constant that records where the major ones are. The tricky part is finding the user’s own location.

    What I’d suggest is to examine timezone settings. You can read Sys.timezone() directly and apply to a lookup table, but that’s a string and it might be a pain. I’d instead try to find the UTC offset, by, e.g.

    tmp = as.POSIXlt(Sys.time())
    offset =  as.numeric(as.POSIXct(format(tmp))) 
             - as.numeric(as.POSIXct(format(tmp, tz = "UTC")))
    

    Then you can look up the offset against some kind of table, and match each band to some repository. Be sure to consider the case where a repository is down, or something…

    To be fair, you can probably get pretty reasonable results by just selecting a random repository. (Maybe excluding some of the ones out in the middle of nowhere…)

    Determining whether repos have been set is a simple matter of looking up options("repos") or getOption("repos"). From ?options:

    ‘repos’: URLs of the repositories for use by ‘update.packages’.
          Defaults to ‘c(CRAN="@CRAN@")’, a value that causes some
          utilities to prompt for a CRAN mirror. 
    

    So (getOption("repos")[1] == "@CRAN@") should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to detect when a window that doesn't belong to my
Is there any way to detect when URL's length is exceeded? This is causing
Is there any way to detect if a commercial is playing? I'm using player.observe(models.EVENT.CHANGE,
Is there a way to detect page breaks with php? I generate a report
is there a way to detect if a header of a section in an
Is there a way to detect whether sys.stdout is attached to a console terminal
Is there any way to detect when an app is no longer active? That
Is there a way to detect when a UITextView has finished scrolling? As a
Is there a way to detect if your program was loaded through Visual Studio
Is there a way to detect if the display css property of an element

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.