Trying to install the Performance Analytics in R - r

I'm trying to install the package 'Performance Analysis' in the R script below:
tryCatch(
expr = {
#library('PerformanceAnalytics', verbose = FALSE, quietly = TRUE)
library("PerformanceAnalytics",lib.loc=.libPaths(),verbose = FALSE, quietly = TRUE)
},
error = function(e){
print(e)
install.packages('PerformanceAnalytics', repos='https://cran.rstudio.com', verbose = FALSE)
#library('PerformanceAnalytics', verbose = FALSE, quietly = TRUE)
library("PerformanceAnalytics",lib.loc=.libPaths(),verbose = FALSE, quietly = TRUE)
}
)
But I'm having the following error message (Version 1.2.1335 of R Studio). Does anyone know if I've made a mistake somewhere?
Thanks
unable to access index for repository https://cran.rstudio.com/bin/windows/contrib/3.1
Installing package into ‘C:/Users/xxxxx/Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
Warning in install.packages :
unable to access index for repository https://cran.rstudio.com/bin/windows/contrib/3.1
Warning in install.packages :
package ‘PerformanceAnalytics’ is not available (as a binary package for R version 3.1.3)
Error in library("PerformanceAnalytics", lib.loc = .libPaths(), verbose = FALSE, :
there is no package called ‘PerformanceAnalytics’

Related

hide package loading message when I render R markdown

I can't get this dplyr package loading message to go away:
package 'dplyr successfully unpacked and MD5 sums checked
And here is my current code:
g <- df$Finished
h <- append(g, rep("dummy",519))
i <- data.frame(counts <- table(h))
row.names(i) <- c("In progress", "Completed", "Invited")
colnames(i) <- c("gh", "Count")
i = subset(i,select = -c(gh))
suppressPackageStartupMessages(install.packages("dplyr", repos = "http://cran.us.r-project.org", quiet = TRUE, message=FALSE))
suppressPackageStartupMessages(library(dplyr, quietly = TRUE, warn.conflicts = FALSE, invisible()))
ii<- i %>%
arrange(desc(Count))
u <- ii %>% mutate(Percentage = (ii[,1]/519)*100)
print(u)
It even says "cannot remove prior installation of package 'dplyr'
It's not a package loading message, it's a package installation message (which is why all the message suppression won't help). You probably shouldn't install the package every time. Try something like
if (!require("dplyr")) {
install.packages("dplyr", repos = "http://cran.us.r-project.org",
quiet = TRUE, message=FALSE))
}
If all else fails you could probably use capture.output() to make sure you had intercepted all output.

R function `require` does not work as expected in `sapply`

I want to check if a bunch of packages are correctly installed (to make a dockerfile crash and not silently continue).
I tried a sapply on a list of package names, and this is what happens.
Note that:
'not_available' is not installed :)
'testthat' is installed.
# to show the invisible output:
> show <- function(x) {cat(x, '\n')}
> show(require('not_available'))
Loading required package: not_available
FALSE
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘not_available’
So far so good, precisely as expected.
> show(require('testthat'))
TRUE
perfect...
> sapply(c('not_available', 'testthat'), require, warn.conflicts = FALSE, quietly = TRUE)
not_available testthat
FALSE FALSE
Warning messages:
1: In if (!loaded) { :
the condition has length > 1 and only the first element will be used
2: In if (!loaded) { :
the condition has length > 1 and only the first element will be used
Wuuut...
why does it warn us? And why is the output incorrect?
> sapply(c('not_available', 'testthat'), function(x) {x})
not_available testthat
"not_available" "testthat"
Oke, so sapply is not betraying me...
> sapply(c('not_available', 'testthat'), function(pkg) {require(pkg, warn.conflicts = FALSE, quietly = TRUE)})
not_available testthat
FALSE FALSE
Eeeh, now the warning is gone, but the answer.... still wrong... why?
Any clue? Expected behaviour would be a returned value with [FALSE TRUE] (relating to 'not_available' and 'testthat').
Alright, it is due to the special 'library' and 'require' behaviour to also work with unquoted values. So the following will demonstrate the failure:
pkgs <- 'testthat'
require(pkgs)
Loading required package: pkgs
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘pkgs’
The solution is to provide 'character.only'
sapply(c('not_available', 'testthat'), require, character.only = TRUE)
not_available testthat
FALSE TRUE
works just fine.

Cannot Install Plotly in R

Attempting to install plotly in R studio 3.6.1 on a work computer.
Running into this error.
Error in if (any(diff)) { : missing value where TRUE/FALSE needed
Traceback gives
4: tools::checkMD5sums(pkgname, file.path(tmpDir, pkgname))
3: unpackPkgZip(foundpkgs[okp, 2L], foundpkgs[okp, 1L], lib, libs_only,
lock)
2: .install.winbinary(pkgs = bins, lib = lib, contriburl = contrib.url(repos,
type2), method = method, available = av2, destdir = destdir,
dependencies = NULL, libs_only = libs_only, quiet = quiet,
...)
1: install.packages("plotly")
Is the checksum not passing? Why would this be?
Thanks

LightGbm in r 3.5.2

I am trying to install Lightgbm library in r 3.5.2.after millions of try i can do so. if anyone know how to install it?
I have try these methods to install lightgbm but always an error occur of such type.
1.
Error in i.p(...) :
(converted from warning) installation of package ‘C:/Users/MUHAMM~1/AppData/Local/Temp/Rtmp4EX73g/file7d81a401a17/lightgbm_2.2.3.tar.gz’ had non-zero exit status
In addition: Warning messages:
1: In untar2(tarfile, files, list, exdir) :
skipping pax global extended headers
2: In untar2(tarfile, files, list, exdir) :
skipping pax global extended headers
2.
Error in lgb.dl(commit = "master", compiler = "vs", repo = "https://github.com/Microsoft/LightGBM", :
could not find function "lgb.dl"
#1
install.packages('devtools')
packageurl <- "http://cran.r-project.org/src/contrib/Archive/lightgbm/lightgbm_3.5.2.tar.gz"
install.packages(packageurl, contriburl=NULL, type="source")
#2
download.file("https://github.com/hadley/lightgbm/archive/master.zip", destfile = "lightgbm.zip")
#3
lgb.dl(commit = "master",libdll = "C:\\xgboost\\LightGBM\\windows\\x64\\DLL\\lib_lightgbm.dll",
# repo = "https://github.com/Microsoft/LightGBM",cores = 2)
#4
lgb.dl(commit = "master", libdll = "C:\\LightGBM\\windows\\x64\\DLL\\lib_lightgbm.dll", # YOUR PRECOMPILED DLL
#repo = "https://github.com/Microsoft/LightGBM")
Error in lgb.dl(commit = "master", compiler = "vs", repo = "https://github.com/Microsoft/LightGBM", :
could not find function "lgb.dl"
#5
lgb.dl(commit = "master", compiler = "vs", # Remove this for MinGW + GPU installation repo = "https://github.com/Microsoft/LightGBM", use_gpu = TRUE)
#6
lgb.dl(commit = "master", compiler = "vs", # Remove this for MinGW + GPU installation repo = "https://github.com/Microsoft/LightGBM",use_gpu = TRUE)
{lgbl.dl} was originally created to make installing {lightgbm} easier, since {lightgbm} had a difficult-to-use installation process.
That package has not kept up with changes in LightGBM, and is no longer necessary to install the R package on Windows, as the original question here mentions.
{lightgbm} is now on CRAN. Run this R code to install it.
install.packages("lightgbm", repos = "https://cloud.r-project.org")

Highlight R syntax using knitr and Package Highlight

I try to highlight my R code using knit and Highlight pachages with Rstudio, but i have errors when kniting;
There's my code :
opts_chunk$set(fig.width=7, fig.height=5)
opts_knit$set(use.highlight = TRUE)
opts_knit$set(out.format = "html")
opts_chunk$set(highlight = TRUE)
opts_knit$set(...., highlight=FALSE)
render_html()
and when compiling, I have that error
Error in library(package = "parser", character.only = TRUE) :
there is no package called 'parser'
I use R 3.0
Thanks in advance
I think I have fixed this problem in the development version, and you can install it from:
install.packages('knitr', repos = 'http://www.rforge.net/', type = 'source')

Resources