├── .Rbuildignore ├── .gitignore ├── DESCRIPTION ├── Makefile ├── NAMESPACE ├── R ├── wget.R └── zzz.R ├── README.md └── man ├── wget_set.Rd └── wget_unset.Rd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | ^CRAN-SUBMISSION$ 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | CRAN-SUBMISSION 2 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: wget 2 | Title: Setting Download Method to 'wget' 3 | Version: 0.0.3 4 | Authors@R: 5 | person("Guangchuang", "Yu", email = "guangchuangyu@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-6485-8781")) 6 | Description: Provides function, wget_set(), to change the method (default to 'wget -c') using in download.file(). 7 | Using 'wget -c' allowing continued downloading, which is especially useful for slow internet connection and for downloading large files. 8 | User can run wget_unset() to restore previous setting. 9 | Imports: 10 | yulab.utils (>= 0.1.7) 11 | License: Artistic-2.0 12 | Encoding: UTF-8 13 | Roxygen: list(markdown = TRUE) 14 | RoxygenNote: 7.3.2 15 | NeedsCompilation: no 16 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PKGNAME := $(shell sed -n "s/Package: *\([^ ]*\)/\1/p" DESCRIPTION) 2 | PKGVERS := $(shell sed -n "s/Version: *\([^ ]*\)/\1/p" DESCRIPTION) 3 | PKGSRC := $(shell basename `pwd`) 4 | 5 | all: rd check clean 6 | 7 | alldocs: rd readme mkdocs 8 | 9 | rd: 10 | Rscript -e 'roxygen2::roxygenise(".")' 11 | 12 | readme: 13 | Rscript -e 'rmarkdown::render("README.Rmd")' 14 | 15 | readme2: 16 | Rscript -e 'rmarkdown::render("README.Rmd", "html_document")' 17 | 18 | build: 19 | cd ..;\ 20 | R CMD build $(PKGSRC) 21 | 22 | build2: 23 | cd ..;\ 24 | R CMD build --no-build-vignettes $(PKGSRC) 25 | 26 | install: 27 | cd ..;\ 28 | R CMD INSTALL $(PKGNAME)_$(PKGVERS).tar.gz 29 | 30 | check: build 31 | cd ..;\ 32 | # Rscript -e 'rcmdcheck::rcmdcheck("$(PKGNAME)_$(PKGVERS).tar.gz", args="--as-cran")' 33 | Rscript -e 'devtools::check()' 34 | 35 | check2: build 36 | cd ..;\ 37 | R CMD check $(PKGNAME)_$(PKGVERS).tar.gz 38 | 39 | bioccheck: 40 | cd ..;\ 41 | Rscript -e 'BiocCheck::BiocCheck("$(PKGNAME)_$(PKGVERS).tar.gz")' 42 | 43 | clean: 44 | cd ..;\ 45 | $(RM) -r $(PKGNAME).Rcheck/ 46 | 47 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(wget_set) 4 | export(wget_unset) 5 | importFrom(yulab.utils,get_cache_element) 6 | importFrom(yulab.utils,update_cache_item) 7 | importFrom(yulab.utils,yulab_msg) 8 | -------------------------------------------------------------------------------- /R/wget.R: -------------------------------------------------------------------------------- 1 | ##' set "download.file.method" to "wget" and "download.file.extra" to "-c" 2 | ##' 3 | ##' setting download method to "wget -c", so that it can continue the download from where it left off. 4 | ##' @title wget_set 5 | ##' @param method download method (wget, default) 6 | ##' @param extra extra parameter (-c, default) 7 | ##' @return No return value, called for side effects 8 | ##' @export 9 | ##' @examples 10 | ##' wget_set() 11 | ##' @author Guangchuang Yu 12 | wget_set <- function(method = "wget", extra = "-c") { 13 | exit_code <- setup_wget() 14 | if (exit_code != 0) { 15 | return() 16 | } 17 | 18 | get_download_setting() 19 | options(download.file.method = method) 20 | options(download.file.extra = extra) 21 | } 22 | 23 | 24 | ##' unset download method setting by `wget_set` 25 | ##' 26 | ##' set the download method and extra parameter back to what it is or NULL if it is not specify 27 | ##' @title wget_unset 28 | ##' @return No return value, called for side effects 29 | ##' @importFrom yulab.utils get_cache_element 30 | ##' @export 31 | ##' @examples 32 | ##' wget_unset() 33 | ##' @author Guangchuang Yu 34 | wget_unset <- function() { 35 | wget_set( 36 | method = get_cache_element("wget", "download.file.method"), 37 | extra = get_cache_element("wget", "download.file.extra") 38 | ) 39 | } 40 | 41 | #' @importFrom yulab.utils update_cache_item 42 | get_download_setting <- function() { 43 | update_cache_item( 44 | item = "wget", 45 | elements = list( 46 | download.file.method = getOption('download.file.method'), 47 | download.file.extra = getOption('download.file.extra') 48 | ) 49 | ) 50 | } 51 | 52 | 53 | setup_wget <- function() { 54 | # exit code: 55 | # 0 for success 56 | # 1 for fail 57 | 58 | has_wget <- yulab.utils:::has_bin("wget") 59 | 60 | if (has_wget) return(0) 61 | 62 | os <- yulab.utils:::which_os() 63 | if (os != "Windows") { 64 | # we assume `wget` is installed in MacOS and Linux 65 | message("Please install wget manually") 66 | return(1) 67 | } 68 | 69 | if (!interactive()) return(1) 70 | 71 | message("wget is not found. Download it?\n") 72 | if (utils::menu(c("Yes", "No")) != 1) { 73 | return(1) 74 | } 75 | 76 | dir <- yulab.utils:::user_dir("wget", appauthor="YuLab") 77 | destfile <- file.path(dir, "wget.exe") 78 | 79 | if (!file.exists(destfile)) { 80 | url <- "https://eternallybored.org/misc/wget" 81 | # current latest version, access date: 2024-08-17 82 | version <- "1.21.4" 83 | 84 | arch <- 32 85 | if (.Platform$r_arch == "x64") { 86 | arch <- 64 87 | } 88 | 89 | url2 <- sprintf("%s/%s/%s/wget.exe", url, version, arch) 90 | yulab.utils:::mydownload(url2, destfile) 91 | } 92 | 93 | PATH <- Sys.getenv('path') 94 | Sys.setenv(path = sprintf("%s;%s", destfile, PATH)) 95 | return(0) 96 | } 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | #' @importFrom yulab.utils yulab_msg 2 | .onAttach <- function(libname, pkgname) { 3 | packageStartupMessage(yulab_msg(pkgname)) 4 | } 5 | 6 | 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## wget: Setting Download Method to "wget -c" 2 | 3 | 4 | The `wget::wget_set()` function will change the default behavior of 'download.file'. The download method will be changed to using "wget -c" so that continued downloading will be supported. User can run `wget::wget_unset()` to restore previous setting. 5 | 6 | All platforms including Linux, MacOS and Windows are supported. 7 | 8 | 9 | ---- 10 | 11 | What you need is to run the `wget::wget_set()` function. Then `download.file()`, `install.packages()` and `BiocManager::install()` will all support continue retrival. 12 | 13 | -------------------------------------------------------------------------------- /man/wget_set.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/wget.R 3 | \name{wget_set} 4 | \alias{wget_set} 5 | \title{wget_set} 6 | \usage{ 7 | wget_set(method = "wget", extra = "-c") 8 | } 9 | \arguments{ 10 | \item{method}{download method (wget, default)} 11 | 12 | \item{extra}{extra parameter (-c, default)} 13 | } 14 | \value{ 15 | No return value, called for side effects 16 | } 17 | \description{ 18 | set "download.file.method" to "wget" and "download.file.extra" to "-c" 19 | } 20 | \details{ 21 | setting download method to "wget -c", so that it can continue the download from where it left off. 22 | } 23 | \examples{ 24 | wget_set() 25 | } 26 | \author{ 27 | Guangchuang Yu 28 | } 29 | -------------------------------------------------------------------------------- /man/wget_unset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/wget.R 3 | \name{wget_unset} 4 | \alias{wget_unset} 5 | \title{wget_unset} 6 | \usage{ 7 | wget_unset() 8 | } 9 | \value{ 10 | No return value, called for side effects 11 | } 12 | \description{ 13 | unset download method setting by \code{wget_set} 14 | } 15 | \details{ 16 | set the download method and extra parameter back to what it is or NULL if it is not specify 17 | } 18 | \examples{ 19 | wget_unset() 20 | } 21 | \author{ 22 | Guangchuang Yu 23 | } 24 | --------------------------------------------------------------------------------