##-------------------------------------------------------------
##
##-------------------------------------------------------------
.github = function(login_gh)
{
pkg = unlist(strsplit(login_gh, "/"))[2]
url_comp = "archive/master.zip"
url_github = "https://github.com"
url_file = file.path(url_github, login_gh, url_comp)
temp = tempfile(pattern = pkg)
result = tryCatch({
suppressWarnings(
download.file(url = url_file,
destfile = temp,
quiet = FALSE,
method = "libcurl"))
}, error = function(e) {
return(TRUE)
})
if(result)
{
unlink(temp)
out = data.frame(Name=pkg, URL=url_file, Download="FALSE", Installed=FALSE, stringsAsFactors = FALSE)
return(out)
} else {
tempd = tempdir()
unzip(temp, exdir=tempd)
pac = file.path(tempd, paste0(pkg, "-master"))
#system2("R", paste0("CMD INSTALL -c ", pkg, "-master"))
## instala os pacotes
pkno = tryCatch({
unload_pac(pkg, verbose = FALSE)
install.packages(pac, repos=NULL, type="source")
}, warning = function(w) { return(pkg)})
unlink(temp)
if(length(pkno)) Installed = FALSE else Installed = TRUE
out = data.frame(Name=pkg, URL=url_file, Download="TRUE", Installed, stringsAsFactors = FALSE)
return(out)
}#end if
#return(pkg)
}#end install.github
##-------------------------------------------------------------
##
##-------------------------------------------------------------
install.github = function(pkgs, verbose = TRUE)
{
GH = sapply(pkgs, .github, USE.NAMES = FALSE)
GH = t(GH)
GH = as.data.frame(GH)
GH$Name = unlist(GH$Name)
GH$URL = unlist(GH$URL)
GH$Installed = unlist(GH$Installed)
out = .aviso_gh(GH, verbose = verbose)
return(invisible(list(Installed = out, Table = GH)))
}
#pk = c("salah3141/toolbox", "vglopes/RLimnology")[]
#install.github(pk)
.aviso_gh =function(GH, verbose = TRUE)
{
av = c("Install Package GitHub", "Error Install")
st = c("Try URL", "Couldn't resolve host name")
pk_inst = GH[GH["Installed"]==TRUE, ][,1]
if(length(pk_inst))
{
ver = unlist(lapply(pk_inst,
function(x)as.character(packageVersion(x))))
pkgok = paste(pk_inst, ver)
if(verbose) mensagem(pkgok, msg = 1, aviso = "Installed packages - GitHub")
out = pk_inst
} else {
out = NULL
}#end if
## packages not installed
pk_ni = GH[GH["Download"]==TRUE & GH["Installed"]==FALSE, ][,1]
if(length(pk_ni)) mensagem(pk_ni, msg=3)
## packages not
pk_ne2 = GH[GH["Download"]==FALSE & GH["Installed"]==FALSE, ][,2]
pk_ne1 = GH[GH["Download"]==FALSE & GH["Installed"]==FALSE, ][,1]
## package is not available
if(length(pk_ne1)) mensagem(paste(paste0("-",pk_ne1, "-"), pk_ne2),
aviso=av[2], subtitulo = st[2])
return(out)
}#end .aviso_gh
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.