Skip to content

[BUG]: Each startup loading of the TwoSampleMR takes 2 minutes. #654

@zxl-sysu

Description

@zxl-sysu

Describe the bug (required)

It happened when I use the package (both the old and the newest version) in a server with poor web connection. The server was located at the intranet of our institution, in which the web setting was not allowed to be change, so I can't do anything to improve the connection quality. Then I notice that when using TwoSampleMR at the server
(just 'library' it at R and do nothing), it always takes 2 minutes or more to load the package. I have never met the problem when using it at machines with good web connection.

Describe the current behaviour you observe (required)

The welcome message of the package was suspended at:
TwoSampleMR version 0.6.22
And it take 2 minutes until the package was loaded to R.

`
t1=Sys.time()
library(TwoSampleMR)

TwoSampleMR version 0.6.22

t2=Sys.time()
t2-t1

Time difference of 2.002952 mins`

I checked the zzz.R file of the package, and I saw this code with some URLs request:

.onAttach <- function(libname, pkgname) {
  packageStartupMessage(paste("TwoSampleMR version", utils::packageVersion("TwoSampleMR"), "\n"))

  b <- suppressWarnings(try(
    jsonlite::read_json(
      "https://raw.githubusercontent.com/MRCIEU/opengwas/main/messages-twosamplemr.json"
    ),
    silent = TRUE
  ))
  if (!inherits(b, 'try-error')) {
    if (length(b) > 0) {
      o <- lapply(b, function(x) {
        # packageStartupMessage(" Message date: ", x[["date"]])
        sapply(x[["message"]], function(j) packageStartupMessage(paste(" ", j)))
      })
    }
  }

  a <- suppressWarnings(try(
    readLines("https://raw.githubusercontent.com/MRCIEU/TwoSampleMR/master/DESCRIPTION"),
    silent = TRUE
  ))

  if (!inherits(a, 'try-error')) {
    latest <- gsub("Version: ", "", a[grep("Version", a)])
    current <- utils::packageDescription('TwoSampleMR')

    test <- utils::compareVersion(latest, current$Version)
    if (test == 1) {
      packageStartupMessage(
        "\nWarning:\nYou are running an old version of the TwoSampleMR package.\n",
        "This version:   ",
        current$Version,
        "\n",
        "Latest version: ",
        latest,
        "\n",
        "Please consider updating using remotes::install_github('MRCIEU/TwoSampleMR')"
      )
    }
  }
}

Then I copied one of the URL such as "https://raw.githubusercontent.com/MRCIEU/opengwas/main/messages-twosamplemr.json" to my terminal, and tested it with:

wget "https://raw.githubusercontent.com/MRCIEU/opengwas/main/messages-twosamplemr.json"

The URL return some welcome message and version check information like what I saw when loading the package at R.

Then I notice that in my server, it takes about 2 minutes to get the response from this API, while it cost only about 0.05 seconds when the web connection was good.
So I think the time cost at waiting the API response is the reason why the package takes too many time to load.

Describe the behaviour you expect (required)

As I have thousands of MR analysis to do in parallel (with every step using local exposure, outcome and reference data, and theoretically needs no web request, cause NO traffic burden to the MRCIEU web server ) , the 2 minutes hang up in each process takes to many time. As this API requests will just response some messages that will not influence the local package settings and analysis, I hope it can get around the request.

R code to reproduce the issue (required)

#Do it in poor web environment
start_time<- Sys.time()
library(TwoSampleMR)
end_time<- Sys.time()
cost_time<- end_time - start_time

Contribute a solution (optional)

Is it possible to disable the checking request or set a timeout for it ? (Such as when it cost more than 5 seconds, stop the request and just load the package at local).

System information

Ubuntu 20.04.3 LTS

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions