Got knit issue with R - r

my code is working but I can not knit that part,Quitting from lines 17-19 (Homework-template.Rmd)
Error in data.frame(Davis$weight) : ÕÒ²»µ½¶ÔÏó'Davis'
Calls: ... withCallingHandlers -> withVisible -> eval -> eval -> data.frame
´ËÍâ: Warning message:
In has_crop_tools() :
Tool(s) not installed or not in PATH: pdfcrop, ghostcript
-> As a result, figure cropping will be disabled.

Agreed with #T.G., indeed. you need to provide a MWE for us to see what is going on. We can't help you without, as much as we'd like to - sorry.
This said, from the little we can see, you are experiencing 2 separate issues: 1 which causes your code to fail: Error in data.frame(Davis$weight): some error with your data.frame as indicated in the error message and 1 which is just a warning, your markdown file should still compile just fine: Warning message: In has_crop_tools() : Tool(s) not installed or not in PATH: pdfcrop, ghostcript -> As a result, figure cropping will be disabled.
This warning message is how I landed on your post, looking for a solution myself... It stems from lines 315 onwards in https://github.com/rstudio/rmarkdown/blob/master/R/util.R. Here is how I "solved" this warning message under Windows, inspired by this GitHub issue thread:
Run tinytex::tlmgr_install("pdfcrop")
Install Ghostscript from this link
Run Sys.setenv(R_GSCMD="C:/Program Files/gs/gs9.53.3/bin/gswin64.exe") (adjust the version number as needed)
If you want to check: Sys.getenv("R_GSCMD") or tools::find_gs_cmd()
Should show what you just typed: "C:/Program Files/gs/gs9.53.3/bin/gswin64.exe" which is the correct path in my case.
Knit your file again - no more warning message.

Related

Knitr Error in Namepace: Cannot knit to PDF or other format

I am trying to create a PDF export of some of my R outputs (tables and graphs). I created a .Rmd document and I have tried to run the simplest of code setting up the document, but I immediately get an error. The same error pops up when I click the "Knit" button at the top of the R studio window.
The code:
---
title: "Example"
author: "Me"
output: pdf_document
---
{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
The error:
Error in namespaceExport(ns, exports) :
undefined exports: Sweave2knitr, all_labels, all_patterns, all_rcpp_labels, asis_output, cache_engines, clean_cache, combine_words, current_input, dep_auto, dep_prev, engine_output, extract_raw_output, fig_chunk, fig_path, hook_ffmpeg_html, hook_gifski, hook_mogrify, hook_movecode, hook_optipng, hook_pdfcrop, hook_plot_asciidoc, hook_plot_custom, hook_plot_html, hook_plot_md, hook_plot_rst, hook_plot_tex, hook_plot_textile, hook_pngquant, hook_purl, hook_r2swf, hook_scianimator, hooks_asciidoc, hooks_html, hooks_jekyll, hooks_latex, hooks_listings, hooks_markdown, hooks_rst, hooks_sweave, hooks_textile, image_uri, imgur_upload, include_app, include_graphics, include_url, inline_expr, is_html_output, is_latex_output, is_low_change, kable, kables, knit, knit2html, knit2pandoc, knit2pdf, knit2wp, knit_child, knit_code, knit_engines, knit_exit, knit_expand, knit_filter, knit_global, knit_hooks, knit_meta, knit_meta_add, knit_params, knit_params_yaml, knit_patterns, knit_print, kni
Calls: loadNamespace ... namespaceImportFrom -> asNamespace -> loadNamespace -> namespaceExport
In addition: Warning message:
S3 methods '$.knitr_strict_list', 'is_low_change.default', 'knit_print.default', 'knit_print.knit_asis', 'knit_print.knit_asis_url', 'knit_print.knitr_kable', 'print.knitr_kable', 'process_group.block', 'process_group.inline', 'process_tangle.block', 'process_tangle.inline', 'sew.character', 'sew.default', 'sew.error', 'sew.html_screenshot', 'sew.knit_asis', 'sew.knit_embed_url', 'sew.knit_image_paths', 'sew.list', 'sew.message', 'sew.recordedplot', 'sew.source', 'sew.warning' were declared in NAMESPACE but not found
Execution halted
I've tried updating all of my packages and restarting R. I've also tried changing the working directory.
It also seems like Knitr package isn't loading (it's not checked in the packages tab). I just tried checking the box and I received a "fatal error" message and R needed to restart. Once it restarted, I was able to check the box without a "fatal error" but the original error still appears in the console.
To solve this issue, I tried uninstalling the Knitr package but received an error:
cannot delete reparse point 'C:\Users\R\win-library\4.1/knitr/R', reason 'There is a mismatch between the tag specified in the request and the tag present in the reparse point'
Warning in install.packages :
cannot remove prior installation of package ‘knitr’
Warning in install.packages :
cannot delete reparse point 'C:\Users\R\win-library\4.1/knitr/R', reason 'There is a mismatch between the tag specified in the request and the tag present in the reparse point'
Warning in install.packages :
restored ‘knitr’
To resolve this, I changed the name of the folder for the package to xxx and then installed the package again without any issues.
Once I had reinstalled, a new error appeared prompting me to install latexpdf.
I tried to Knit the document again and a new error appeared which lead me to this post: Failed to compile test.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See test.log for more info. Execution halted
As stated in that StackOverflow answer, I ran tinytex::install_tinytex()
After doing this I was able to knit a PDF

RStudio v1.1.456 Rpubs upload error, no login prompt

Hi I couldn't find any useful information in regards to this one.
When I try to publish to Rpubs on Rstudio v1.1.456, instead of login prompt I get this error message below.
[Edited] Rstudio v1.1.456, R v3.5.1
Upload Error Occurred Error in if (result$status == 201) succeeded <-
TRUE : missing value where TRUE/FALSE needed Calls: In
addition: Warning message: In http(protocol, "api.rpubs.com", port,
method, path, headers, : NAs introduced by coercion Execution
halted
I've already addded this line
options(rpubs.upload.method = "internal")
to both global and working directory Rprofile
Apparently, there was an issue in the most recent version of rsconnect (0.8.12).
devtools::install_github("rstudio/rsconnect", ref = "bugfix/multi-status-header")
Installing the patch solves it.

Error in x[[method]](...) : attempt to apply non-function in testthat test when sourcing file

I am developing an R app and came up with a workaround to integrate testthat in it (it usually requires your project to be a package) by adding a DESCRIPTION file to the project root.
I got this method from a colleague who managed to get it to work like this.
The problem is, when I try to test anything (even empty test files), I get this error:
Error in x[[method]](...) : attempt to apply non-function
Calls: <Anonymous> ... <Anonymous> -> o_apply -> lapply -> FUN -> <Anonymous>
Execution halted
What I know is that this appears only on macOS. My colleague can still run this app without problems on Windows.
What's the deal with it?
The MCVE for reproducing this error would be:
create a minimum DESCRIPTION file with content:
Package: testpckg
add testthat to your project:
usethis::use_testthat()
usethis::use_test("foo")
create empty file bar.R
in test-foo.R, source bar: source("bar.R")
RStudio Version 1.1.447,
R version 3.4.4, Mac OS X 10_13_4
This appears to be due to a bug in testthat 2.0.0. Adding a context("Name of test context") to the top of each test file worked for me (tested using Ubuntu and Windows).

The app is disconnected after a second

I ran shiny app in linux.
I open the browser in the url: http://192.241.147.231:4949/sample-apps/MonitorUI/
The page is open but after a second disconnected.
I check the log file and it write to me this massage:
Error in eval(expr, envir, enclos) :
You are attempting to load an rmarkdown file, but the
rmarkdown package was not found in the library. Ensure that
rmarkdown is installed and is available in the Library of the
user you're running this application as.
Calls: local -> eval.parent -> eval -> eval -> eval -> eval
Execution halted
I already downloaded the "rmarkdown" package. and it updated.
What is the problem? i don't find anything for this problem in the web.
the sample app that given by shiny-server package:http://192.241.147.231:4949/sample-apps/hello/ is working so what is the problem?
Thanks.

Error with knitr on texmaker

I am trying for the first time to get knitr running on texmaker, I followed this documentation and I am on Windows 7. However, when I compile, I get the following error stack:
Process started
Error in readLines(if (is.character(input2)) { : cannot open the connection Calls: <Anonymous> -> knit -> readLines
In addition: Warning message: In readLines(if (is.character(input2)) { : cannot open file 'try_easy.Rnw': No such file or directory
Execution halted
Process exited with error(s)
I tried to google it, but only found references to linux/unix, which were not helpful for my case. Following is my short test document:
\documentclass[a4paper]{article}
\begin{document}
<<a>>=
x=rnorm(100)
<<b>>=
<<a>>
mean(x)
#
\end{document}
It's my first time on stackoverflow, so please tell me if you need more information or I did something wrong. Thank you very much.
Update
Hello everyone,
I managed to find out my mistake. For the sake of future google-searchers, I had saved the file as a .tex instead as .rnw. Saving as rnw solved it. Since I cannot answer my own questions, I edit it here.
This error happens when the file is saved as a .tex instead of a .Rnw, as the compiler does not know that he should "knitr-compile" files that have the .tex handle, unless you specifically set him up like that.

Resources