Problems installing github - r

Hi I have a problem with github package.
This is my code:
Installing packages:
install.packages("magrittr")
library(magrittr)
install.packages("ggplot2")
library(ggplot2)
install.packages("cowplot")
library(cowplot)
install.packages("usethis")
library(usethis)
install.packages("devtools")
library(devtools)
Here comes the error , when I try to force the installation:
There are 4 options:
1: All
2: CRAN packages only
3: None
4: tibble (2.1.3 -> 3.0.0) [CRAN]
When I press 1 I get this error message:
Installing 1 packages: tibble
Installing package into ‘C:/Users/josem/OneDrive/Documents/R/win-library/3.6’
(as ‘lib’ is unspecified)
There is a binary version available but the source version is later:
binary source needs_compilation
tibble 2.1.3 3.0.0 TRUE
Error: Failed to install 'JLutils' from GitHub:
(converted from warning) package ‘tibble’ is in use and will not be installed
devtools::install_github("larmarange/JLutils", force= TRUE)
install.packages("tidyverse")
library(tidyverse)
library(plyr)
library(dplyr)
library(JLutils)
library(tidyverse)
install.packages("rio")
library(rio)
Then when I choose option 3 I can download jutils package but I can not create dat2 dataframe. I don't know why. It's really frustrating ( yesterday it worked perfectly)`
dat <- rio::import("https://github.com/jincio/COVID_19_PERU/blob/master/docs/reportes_minsa.xlsx?raw=true")
dat1 <- dat %>%
mutate(pos_new = Positivos-lag(Positivos,default = 0),
des_new = Descartados-lag(Descartados,default = 0)) %>%
group_by(Dia) %>%
summarise(pos_new = sum(pos_new), des_new = sum(des_new)) %>%
mutate(cum_pos = cumsum(pos_new),
tot_pruebas = pos_new+des_new)
Here is the error:
(creating dat2):
Error in .f(.x[[i]], ...) : object 'Dia' not found
dat2 <- dat1 %>%
mutate(neg_new = tot_pruebas-pos_new) %>%
dplyr::select(Dia, pos_new, neg_new) %>%
rename(Positivo = pos_new, Negativo = neg_new) %>%
gather(res, count, -Dia) %>%
uncount(count)
I tried everything :(

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.

How old is an installed R package?

Is it possible to get the year that an installed R package is released using some R code? I can get the version, but then have to look it up on the internet, when this version was released.
Background: I am working for the Swiss Federal Statistical Office and a small group is trying to get a better R environment (we are working for example with the dplyr version 0.7.4 from 2017... and it is not possible to install a newer version...).
Cheers
Renger
You can use versions package to get a timestamp of package version. The package pulls the published versions of the package from the MRAN snapshot server.
versions::installed.versions("dplyr")
# [1] "1.0.7"
versions::available.versions("dplyr")
# $dplyr
# version date available
# 1 1.0.7 2021-06-18 TRUE
# 2 1.0.6 2021-05-05 TRUE
# 3 1.0.5 2021-03-05 TRUE
# ...
Package age
So if you want to answer the specific question about the package age you can do the following:
how_old <- function(pkg, lib = .libPaths()[1], return_age = FALSE) {
pkg_ver <- versions::installed.versions(pkgs = pkg, lib = lib)
av_vers <- versions::available.versions(pkgs = pkg)
pkg_dte <- subset.data.frame(
x = as.data.frame(unname(av_vers)),
subset = version == pkg_ver,
select = date,
drop = TRUE
)
pkg_dte <- as.Date(pkg_dte)
if (return_age) {
return(epocakir::dob2age(dob = pkg_dte))
} else {
return(pkg_dte)
}
}
how_old("dplyr", return_age = TRUE)
Results
[1] "1123200s (~1.86 weeks)"
Package creation
Or if you want to find out when package was installed locally.
when_created <- function(pkg, lib = .libPaths()[1]) {
# Package will always have DESCRIPTION file so that's a safe bet
desc_file <- system.file("DESCRIPTION", package = pkg, lib.loc = lib)
info <- fs::file_info(desc_file)
info$birth_time
}
when_created("dplyr")
Results
# [1] "2021-06-25 08:47:21 BST"
As #Jonathan recommended, if the package has a citation, then you can call the year in the citation.
citation("dplyr")$year
An alternative is to get the date from a list of available versions of a package.
devtools::install_github("https://github.com/cran/versions")
library(versions)
x <- versions::available.versions(c("dplyr", "ggplot2"))
version_year <-
function(x,
package.name = "",
version = "") {
pckg <- x[[package.name]]
row <- which(pckg$version == version)
return(pckg$date[row])
}
version_year(x, "ggplot2", version = "2.0.0")
#[1] "2015-12-18"
As a last resort, you can find out when a package was created from its DESCRIPTION:
packageDescription(pkg)$Packaged
In fact, citation falls back to this very field if no other date was given (either as Date/Publication or via an explicit CITATION file).

why can't I use the functions from prophet packages?

I'm not using CSV data. Is that will be a problem?
Every time I run this it will be shown couldn't find function "prophet" or "make_future_dataframe"
This is the data i use
resp_jakarta <- GET("https://data.covid19.go.id/public/api/prov_detail_DKI_JAKARTA.json")
status_code(resp_jakarta)
cov_jakarta_raw <- content(resp_jakarta, as = "parsed", simplifyVector = TRUE)
cov_jakarta <- cov_jakarta_raw$list_perkembangan
new_cov_jakarta <-
cov_jakarta %>%
select(-contains("DIRAWAT_OR_ISOLASI")) %>%
select(-starts_with("AKUMULASI")) %>%
rename(
kasus_baru = KASUS,
meninggal = MENINGGAL,
sembuh = SEMBUH
) %>%
mutate(
tanggal = as.POSIXct(tanggal / 1000, origin = "1970-01-01"),
tanggal = as.Date(tanggal)
)
#Forecast
install.packages("prophet")
trying URL https://cran.rstudio.com/bin/macosx/contrib/4.0/prophet_0.6.1.tgz
Content type 'application/x-gzip' length 6317112 bytes (6.0 MB)
downloaded 6.0 MB
The downloaded binary packages are in
/var/folders/bl/q861y47s7b7cnym8hzmryv0c0000gn/T//RtmpTKLo8z/downloaded_packages
library(prophet)
This happens when i run library(prophet)
Loading required package: Rcpp
Loading required package: rlang
Error: package or namespace load failed for ‘prophet’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/prophet/libs/prophet.so':
dlopen(/Library/Frameworks/R.framework/Versions/4.0/Resources/library/prophet/libs/prophet.so, 6): Library not loaded: #rpath/libtbb.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/prophet/libs/prophet.so
Reason: image not found
date=as.Date(new_cov_jakarta$tanggal)
cases=new_cov_jakarta$kasus_baru
temp_prophet <- data.frame(date,cases)
temp_prophet <- temp_prophet %>% rename(ds = date, y = cases)
#Issues start from here
m <- prophet(temp_prophet)
And then this happens:
Error in prophet(temp_prophet) : could not find function "prophet"
future <- make_future_dataframe(m, periods = 30,freq="day")
Error in make_future_dataframe(m, periods = 30, freq = "day") : could not find function "make_future_dataframe"
tail(future)
forecast <- predict(m, future)
That's already been reported as an issue in prophet, and was suggested to install the package from source in order to fix it:
install.packages("prophet", type="source")
Also, double-check that both prophet.so and libtbb.dylib exist in your system.

reprex showing correct output but rstudio console is showing error

library(tidyverse)
#> Warning: package 'tidyverse' was built under R version 3.6.3
#> Warning: package 'ggplot2' was built under R version 3.6.3
#> Warning: package 'tidyr' was built under R version 3.6.3
#> Warning: package 'purrr' was built under R version 3.6.3
#> Warning: package 'dplyr' was built under R version 3.6.3
#> Warning: package 'stringr' was built under R version 3.6.3
#> Warning: package 'forcats' was built under R version 3.6.3
mtcars = as_tibble(mtcars)
cars_nested = mtcars %>% group_by(cyl) %>% nest()
cars_fitted = cars_nested %>%
mutate(fit = map(data, function(x) lm(mpg ~ disp, data = x)))
Created on 2020-07-29 by the reprex package (v0.3.0)
When I ran this code in Rstudio, I am getting the following errors. Any help?
> mtcars = as_tibble(mtcars)
> cars_nested = mtcars %>% group_by(cyl) %>% nest()
> cars_fitted = cars_nested %>%
+ mutate(fit = map(data, function(x) lm(mpg ~ disp, data = x)))
Error: Problem with `mutate()` input `fit`.
x object 'disp' not found
i Input `fit` is `map(data, function(x) lm(mpg ~ disp, data = x))`.
i The error occured in group 1: cyl = 4.
Run `rlang::last_error()` to see where the error occurred. ```
Thanks for the suggestions. I found why I am getting these errors. In the earlier code, I unknowingly nested the mtcars to the same mtcars dataset. So there are only cyl and data columns. Thats why I got the error.

pkgdown htmlwidget - Examples

I have tried pkgdown for many htmlwidgets but no example work. They all return the same error:
USArrests %>%
dplyr::mutate(
State = row.names(.),
Rape = -Rape
) %>%
e_charts(State) %>%
e_bar(Murder) %>%
e_bar(Rape, name = "Sick basterd", x.index = 1) # second y axis
#> Error in yaml.load(readLines(con), error.label = error.label, ...): argument "error.label" is missing, with no default
Reverting yaml package version did not help.
Upgrading to pandoc 2.1.3 did not help either.
Sadly htmlwidgets are not supported in pkgdown at the time of writing this, see issues 617 and 343.

Resources