Error there is no package called RevoUtilsMath with R Markdown - r

I am running R 3.4.3 and 3.5.1 (non-Microsoft version) and RStudio version 1.1.456. I am trying to knit some code into RMarkdown. However, I get the following error:
Error in library(p, character.only = TRUE) : there is no package called 'RevoUtilsMath'Calls: <Anonymous> ... suppressPackageStartupMessages -> withCallingHandlers -> library
Execution halted
The package RevoUtilsMath is part of the MKL install with Microsoft R. I cannot install it as a supplemental package with 'regular R'. The script itself runs fine, it just does not work in R Markdown.
The following libraries are loaded:
```{r loadLibraries, echo=FALSE, warning=FALSE}
library(RODBC)
library(dplyr)
library(markovchain)
library(DT)
library(reshape2)
library(knitr)
library(ggplot2)
library(scales)
library(PerformanceAnalytics)
library(plotly)```
The missing package error happens when executing the code below in Markdown. It is called using this code.
```{r histogram1, echo=FALSE, cache=TRUE}```
The histogram1 code is below (very standard ggplot).
g <- ggplot(dataClean, aes(x = IncSnapshotDay, fill = Represent)) +
geom_histogram(bins=70, alpha = .8) +
scale_fill_manual(values = colors) +
scale_x_continuous(labels = comma, limits = c(0,40000)) +
facet_wrap(~SnapshotDay) +
ylim(0,4000) +
theme_bryan()
g
I thought that maybe one of these packages has a dependency, so I ran the following to find out.
library(tools)
> dependsOnPkgs('RevoUtilsMath')
It returns character(0) which indicates that none of the packages depend on it. I did a test of the function on ggplot2, and it works
dependsOnPkgs('ggplot2')
[1] "dendextend" "GGally" "ggthemes" "plotly" "viridis" "caret" "crosstalk"
[8] "DT"
So why does R Markdown/knitr generate this error since the code itself runs fine outside of Markdown, and how do I fix this?

I think you are experiencing a problem similar to one I just had though, without more detail, it is hard for me to know.
In my case, the problem was caused by knitr caching the list of packages used by a previous author (using Microsoft R). The immediate solution was to simply clear the knitr cache (via the "Knit" drop down menu in RStudio) before attempting to knit the code.
I still don't really understand why this is happening or how to avoid it in future situations, but this at least provides a way to create the document even in the face of this behavior.

Related

Why does R Markdown not want to Knit with spss file?

I performed a multilevel analysis in R (following Kay Chansiri's tutorial but using my df). It worked as it should, but then I wanted to do it again in R Markdown so as to make it into a report. The code works fine in R Markdown, but it will not knit it. Everything seems to revolve around the spss file I am using.
Here is the code from the first chunk:
```{r MLM_deJong}
MLM_deJong<-read_sav("dataset_MA2.sav")
View(MLM_deJong)
```
And the next chunk:
```{r}
MLM_deJong = MLM_deJong %>% replace_with_na(replace = list(business = 999))
mean(MLM_deJong$business, na.rm = T)
MLM_deJong$business[is.na(MLM_deJong$business)] <- mean(MLM_deJong$business, na.rm = T)
```
and so on...
R imports the df and performs all the operations. But when I want to knit it, here is what the R Markdown tab in the console writes:
Line 46Error in read_sav("dataset_MA2.sav) : could not find function "read_sav" calls: ... handle -> withCallHandlers -> withVisible -> eval -> eval.
Needless to mention, no file is knit.
I have of course installed the 'haven' package. The same occurs when I tried read.spss through the 'foreign' package.
Even though you have installed the haven package, it is not automatically loaded when rmarkdown knits.
Option 1: Load the haven package before you use it.
library(haven)
MLM_deJong<-read_sav("dataset_MA2.sav")
Option 2: Prepend haven:: to read_sav
MLM_deJong<-haven::read_sav("dataset_MA2.sav")

Rmarkdown problems witk 'knirt' in presentation

I am new here and I want to explain my problem.
I wrote the following code to install Rmarkdown (I have the packages in specific place in mi hard disk D)
.libPaths(c("D:/R_Packages", .libPaths()))
install.packages("rmarkdown",dependencies=TRUE)
install.packages("knitr", dependencies = TRUE)
install.packages("knitLatex",dependencies = TRUE)
install.packages("learnr")
install.packages('tinytex')
tinytex::install_tinytex()
library(knitr)
library(knitLatex)
library(learnr)
library(tinytex)
library(rmarkdown)
and almost all works good but when I tried with R presentation, in the windows of presentation said this:
Error in library(knitr) : there is no package called 'knitr'
Execution halted
If someone can help me to solve the problem I will appreciate it very much.

RMarkdown: "Error: path for html_dependency not found:"

I am a Chemist who uses R and R Studio to analyze mass spectrometry data. I have automated scripts that process my data, because there are a lot of files. The scripts call rmarkdown using render() to import data, manipulate the data frame, save the processed data frame as a .csv and generate an html of plots. I have a problem rendering rmarkdown files since I recently updated to R v3.5.1 and R Studio v1.1.463. The error I receive is: Error: path for html_dependency not found: which I get if I use the knit button in R Studio, or if I use render(). The script inside the rmarkdown runs to completion, as the resulting objects are present in the environment window in R Studio, but the html file doesn’t render, and I get the error which stops the loop of render() I use to process all the files in a specific folder. This is a process I have done many times before updating.
I ran traceback() and got the following results:
8: stop("path for html_dependency not found: ", file, call. = FALSE)
7: FUN(X[[i]], ...)
6: lapply(dependencies, validate_html_dependency)
5: dependency_resolver(all_dependencies)
4: html_extras_for_document(knit_meta, runtime, dependency_resolver,
format_deps)
3: base(...)
2: output_format$pre_processor(yaml_front_matter, utf8_input, runtime,
knit_meta, files_dir, output_dir)
1: render("Processing and QA Template_INT_FINAL_MFAssignR.rmd",
output_file = paste0(substr(file_list[i], 1, nchar(file_list[i]) -
4), ".html"), output_dir = folder, params = list(data = file_list[i], path = folder))
I have uninstalled and reinstalled packages several times. I even removed my library folder entirely once, then reinstalled. My packages are up to date, but I had problems installing packages since the update, including rmarkdown. I had to use install.packages(“package”, type=”binary”) to install the dependencies for rmarkdown in order to get it to install. Normally I can just use the Install button in R Studio.
This is a work PC (Windows 10, 64 bit) I do not have administrator access to. I have to uninstall/install through IT at my university, which is a hassle, so I want to come to them with a plan. My package library defaults to a network drive that I can read/write to, and I have limited access to the hard disks; either way I can’t seem to change where packages are installed in R Studio. I don’t know if I can re-install an older version of R and R Studio or if it would help. A lot of the packages I use are developed for the current version of R and I was having some other issues, which was why I updated in the first place. The exact same scripts and data files run properly on another PC (my personal laptop, which is also up to date on R, R Studio and packages); the only changes I made are to the working directory so the data loads properly. I also had no trouble installing packages.
Here is an example of my code; since my scripts are very long, complicated and data specific, I have prepared a more simplified version of what they do as an example. I really don’t think there is anything wrong with the scripts themselves, as I mentioned before I have run them many times before the update. I suspect something is wrong with either the install of R, R studio or rmarkdown.
The main script, which calls render() from rmarkdown:
setwd("D:/Working Directory")
library("rmarkdown")
folder=paste0(getwd(),"/")
file_list=list.files(path=folder, pattern="*_MF.csv")
for (i in 1:length(file_list)){
render("Processing and QA Template.rmd",
output_file = paste0(substr(file_list[i],1, nchar(file_list[i])-4),".html"), output_dir = folder,
params=list(data=file_list[i], path=folder))
}
The rmarkdown, named “Processing and QA Template.rmd” which is in "D:/Working Directory":
---
title: "Example Processing and QA"
author: "Matt Brege "
date: "2018-12-12"
output: html_document
params:
data: x
path: x
---
```{r, echo=FALSE, message=FALSE}
library(dplyr)
library(ggplot2)
library(tidyr)
file_name <- substr(params$data, 1, nchar(params$data)-7)
folder <- params$path
input <- tbl_df(read.csv(paste0(file_name, "_MF.csv"), stringsAsFactors = FALSE))
```
```{r, echo=FALSE}
#...a series of long and complicated data manipulations later…
write.csv(input7, paste0("Output/", file_name, "_QAd.csv"), row.names=FALSE, na="")
```
```{r,r, echo=FALSE, warning=FALSE, message=FALSE}
#...plotting section…
# these are just examples
p1 <-ggplot(diamonds, aes(x=carat, y=price)) + geom_point()
print(p1)
p2<- ggplot(diamonds, aes(x=carat, y=price, color=clarity)) + geom_point()
print(p2)
p3<- ggplot(diamonds, aes(x=carat, y=price, color=cut)) + geom_point()
print(p3)
```
Finally, I have found the following similar posts about what appears to be the same issue, but they are old and from different versions of R, and it doesn’t seem like it was resolved in those instances anyway:
RMarkdown cannot knit: html_dependency not found
RNotebook cannot output due to html_dependency not found
R looks in the wrong place for html dependency
One suggestion from the last link was to clear the cache: “If you cached the chunk containing HTML widgets, you may need to invalidate the cache after you update R packages. – Yihui Xie Dec 6 '17 at 19:00” but I am not exactly sure what that means or how to do it. I generally run cat("\014") and rm(list=ls()) at the beginning of each script, but I don’t know if that’s what the suggestion means, and it has not helped.
I got it to work by:
Clear Knitr Cashe... (see the little arrow next to the Knit-icon in RStudio).
I also had to restart R (.rs.restartR() ).

Error while knitting a LaTeX file: could not find function "as"

I am trying to knit a chunk embedded in a latex file with extension Rnw.
library(ggplot2)
library(flexclust)
library(arules)
data(Groceries)
Gr <- Groceries[, itemFrequency(Groceries) > 0.02]
grc <- as(Gr, "matrix")
I get this error:
#Error in as(Gr, "matrix") could not find function "as"
The same commands work perfectly well in R
Any ideas?
When in doubt, try to upgrade your software packages. If you are using a recent version of R (>= 3.5.0), you should not need to library(methods), because it will be loaded (attached) by default. This problem (Rscript does not load methods) has existed in base R for many years until this year and surprised/confused many users. If you have to use an old version of R, you will need library(methods) explicitly.

slidify + data.table( ggplot2) error

when i try to add (data.table/ggplot2)code in slidify, i got error.
Here is my code in slidify:
## data.table
```{r}
library(data.table)
DT = data.table(x = 1:5, y=6:10)
setkey(DT, x)
DT[J(1)] # Error: No J function
```
---
## ggplot2
```{r}
library(ggplot2)
a = b = shape = 1:5
ggplot(data=DT, aes(a, b, col=shape)) + geom_point() # Error: can not find object a
```
All the code can run outside slidify, so i guess there is something about variable namespace wrong with slidify.
I also find this link:data.table error when used through knitr, gWidgetsWWW which might be similar with my problem, but still don't know how to fix.
Just to add an answer to follow up on the comments on the question. The dev version of data.table fixed it and is now on CRAN (data.table v1.9.4). But this broke kable() in knitr which knitr v1.7 (on CRAN too) fixes.
So basically, upgrade to latest CRAN versions of knitr and data.table and you should be fine. Please let us know if not.
More detail for the curious ...
I've made another change to data.table in v1.9.5 to make it more robust for packages that evaluate user code (like knitr, slidify and gWidgetsWWW) but don't know about data.table themselves. So that they don't need to know in future. Here is the item :
knitr::kable() works again without needing to upgrade from knitr v1.6 to v1.7. Packages which evaluate user code and don't wish to import data.table need to be added to data.table:::cedta.pkgEvalsUserCode and now only the eval part is made data.table-aware (the rest of such package's code is left data.table-unaware). data.table:::cedta.override is now empty and will be deprecated if no need for it arises.
And here is the item in v1.9.4 that was a little too over-reaching and broke knitr::kable in knitr v1.6 and knitr v1.7 fixes (but shouldn't have needed to) :
Added shiny, rmarkdown and knitr to the data.table whitelist. Packages which take user code as input and run it in their own environment (so do not Depend or Import data.table themselves) either need to be added here, or they can define a variable .datatable.aware <- TRUE in their namepace, so that data.table can work correctly in those packages. Users can also add to data.table's whitelist themselves using assignInNamespace() but these additions upstream remove the need to do that for these packages.

Resources