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")
I am trying to follow the tutorial from Seurat website.
https://satijalab.org/seurat/v3.1/pbmc3k_tutorial.html
I got an error when loading the data.
Load the PBMC dataset
pbmc.data <- Read10X("1_Guided_tutorial/pbmc3k_filtered_gene_bc_matrices.tar.gz")
Error in Read10X("1_Guided_tutorial/pbmc3k_filtered_gene_bc_matrices.tar.gz") :
Directory provided does not exist
I have set my working directory as the image showed. Can anyone let me know what is the problem? Thank you!
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("multtest")
library(dplyr)
library(Seurat)
library(patchwork)
# Load the PBMC dataset
pbmc.data <- Read10X(data.dir = "1_Guided_tutorial/pbmc3k_filtered_gene_bc_matrices.tar.gz")
I was trapped with this problem few minutes before, and I find the solution now.
Try to use these codes:
install.packages("Seurat")
library(Seurat)
install.packages(c('dplyr','patchwork'))
library(dplyr)
library(Seurat)
library(patchwork)
in order to install the environment for scRNA analysis
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() ).
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.
I tried to use get_rollit_source from the RcppRoll package as follows:
library(RcppRoll)
get_rollit_source(roll_max,edit=TRUE,RStudio=TRUE)
I get an error:
Error in get("outFile", envir = environment(fun)) :
object 'outFile' not found
I tried
outFile="C:/myDir/Test.cpp"
get_rollit_source(roll_max,edit=TRUE,RStudio=FALSE,outFile=outFile)
I get an error:
Error in get_rollit_source(roll_max, edit = TRUE, RStudio = FALSE, outFile = outFile) :
File does not exist!
How can fix this issue?
I noticed that the RcppRoll folder in the R library doesn't contain any src directory. Should I download it?
get_rollit_source only works for 'custom' functions. For things baked into the package, you could just download + read the source code (you can download the source tarball here, or go to the GitHub repo).
Anyway, something like the following should work:
rolling_sqsum <- rollit(final_trans = "x * x")
get_rollit_source(rolling_sqsum)
(I wrote this package quite a while back when I was still learning R / Rcpp so there are definitely some rough edges...)