Knitr error when running R Markdown from batch - r

I was following this SO answer to create a batch file that runs an R script, which in turn runs a Markdown file.
In short. The test version has three parts.
I. R Script - knits and renders the markdown:
library(knitr)
library(rmarkdown)
setwd("~/r_directory")
knit("test_markdown.Rmd")
render("test_markdown.Rmd")
Sys.sleep(3)
II. R Markdown file
---
title: "Test"
output: html_document
---
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
```{r cars}
summary(cars)
```
III. Batch file:
"C:\Program Files\R\R-3.4.3\bin\R.exe" CMD BATCH --vanilla --slave "C:\Users\Stefan\Documents\r_directory\script.R" "C:\Users\Stefan\Documents\r_directory\script.Rout"
Now I'm getting two types of errors in the script.Rout file.
With the correct R.Script version the error I'm getting is:
Error in library(knitr) : there is no package called 'knitr'
Execution halted
So, ok. Obviouslly I should install knitr.
But when I change the script to include - install.packages("knitr"), I get:
Installing package into 'C:/Users/Stefan/Documents/R/win-library/3.4'
(as 'lib' is unspecified)
Error in contrib.url(repos, "source") :
trying to use CRAN without setting a mirror
Calls: install.packages -> contrib.url
Execution halted
Any idea where I'm missing something?
Edit: I provided multiple repos for the knitr package.
install.packages('knitr', repos = c('http://cran.rstudio.org', 'http://cran.us.r-project.org', 'http://rforge.net'),
type = 'source')
What I get as an error now is:
Installing package into 'C:/Users/Stefan/Documents/R/win-library/3.4'
(as 'lib' is unspecified)
also installing the dependencies 'mime', 'stringi', 'evaluate', 'markdown', 'stringr', 'yaml'
trying URL 'http://rforge.net/src/contrib/mime_0.5.1.tar.gz'
Content type 'application/x-gzip' length 11695 bytes (11 KB)
==================================================
downloaded 11 KB
trying URL 'http://cran.rstudio.org/src/contrib/stringi_1.1.6.tar.gz'
Content type 'application/x-gzip' length 3647049 bytes (3.5 MB)
==================================================
downloaded 3.5 MB
trying URL 'http://rforge.net/src/contrib/evaluate_0.10.3.tar.gz'
Content type 'application/x-gzip' length 19612 bytes (19 KB)
==================================================
downloaded 19 KB
trying URL 'http://rforge.net/src/contrib/markdown_0.8.1.tar.gz'
Content type 'application/x-gzip' length 88252 bytes (86 KB)
==================================================
downloaded 86 KB
trying URL 'http://cran.rstudio.org/src/contrib/stringr_1.2.0.tar.gz'
Content type 'application/x-gzip' length 94095 bytes (91 KB)
==================================================
downloaded 91 KB
trying URL 'http://cran.rstudio.org/src/contrib/yaml_2.1.16.tar.gz'
Content type 'application/x-gzip' length 85275 bytes (83 KB)
==================================================
downloaded 83 KB
trying URL 'http://cran.rstudio.org/src/contrib/knitr_1.19.tar.gz'
Content type 'application/x-gzip' length 649805 bytes (634 KB)
==================================================
downloaded 634 KB
* installing *source* package 'mime' ...
** libs
*** arch - i386
Warning: running command 'make -f "C:/PROGRA~1/R/R-34~1.3/etc/i386/Makeconf" -f "C:/PROGRA~1/R/R-34~1.3/share/make/winshlib.mk" SHLIB="mime.dll" OBJECTS="init.o rawmatch.o"' had status 127
ERROR: compilation failed for package 'mime'
* removing 'C:/Users/Stefan/Documents/R/win-library/3.4/mime'
In R CMD INSTALL
* installing *source* package 'stringi' ...
** package 'stringi' successfully unpacked and MD5 sums checked
Warning: running command 'sh ./configure.win' had status 127
ERROR: configuration failed for package 'stringi'
* removing 'C:/Users/Stefan/Documents/R/win-library/3.4/stringi'
In R CMD INSTALL
* installing *source* package 'yaml' ...
** package 'yaml' successfully unpacked and MD5 sums checked
** libs
*** arch - i386
Warning: running command 'make -f "Makevars" -f "C:/PROGRA~1/R/R-34~1.3/etc/i386/Makeconf" -f "C:/PROGRA~1/R/R-34~1.3/share/make/winshlib.mk" SHLIB="yaml.dll" OBJECTS="api.o dumper.o emitter.o implicit.o loader.o parser.o r_emit.o r_ext.o r_parse.o reader.o scanner.o writer.o"' had status 127
ERROR: compilation failed for package 'yaml'
* removing 'C:/Users/Stefan/Documents/R/win-library/3.4/yaml'
In R CMD INSTALL
ERROR: dependency 'mime' is not available for package 'markdown'
* removing 'C:/Users/Stefan/Documents/R/win-library/3.4/markdown'
In R CMD INSTALL
ERROR: dependency 'stringi' is not available for package 'stringr'
* removing 'C:/Users/Stefan/Documents/R/win-library/3.4/stringr'
In R CMD INSTALL
ERROR: dependency 'stringr' is not available for package 'evaluate'
* removing 'C:/Users/Stefan/Documents/R/win-library/3.4/evaluate'
In R CMD INSTALL
ERROR: dependencies 'evaluate', 'markdown', 'stringr', 'yaml' are not available for package 'knitr'
* removing 'C:/Users/Stefan/Documents/R/win-library/3.4/knitr'
In R CMD INSTALL
The downloaded source packages are in
'C:\Users\Stefan\AppData\Local\Temp\RtmpaiQed8\downloaded_packages'
There were 14 warnings (use warnings() to see them)
Error in library(knitr) : there is no package called 'knitr'
Execution halted

Related

Non-zero exit status: "shinymanager" on Ubuntu EC2 AWS

I am trying to host a shiny app on an AW2 instance with ubuntu. This is the first time I have tried using an EC2 instance and the last package I need to install, "shinymanager" for the app is giving a non-zero exit status. Please let me know how to install "shinymanager" to the shiny-server on my ubuntu ec2 instance.
Ubuntu version: 18.04+
R version: R version 4.1.2 (2021-11-01) -- "Bird Hippie"
All the below packages have installed successfully through this method:
/srv/shiny-server$ sudo R
install.packages(c("package name"), dependencies = T)
Packages present in Global file that installed properly
library(tidyverse)
library(here)
library(janitor)
#library(lubridate)
#library(RPostgres)
#library(rstudioapi)
library(shinyWidgets)
library(DT)
#library(glue)
library(shinycssloaders)
#library(DBI)
library(gargle)
library(shinyalert)
library(googledrive)
library(shinylogs)
library(cachem)
library(shinymanager)
Here is the data and error I receive when trying install.packages("shinymanager", dependencies = T)
install.packages("shinymanager", dependencies = T)
Installing package into ‘/root/R/x86_64-pc-linux-gnu-library/4.1’
(as ‘lib’ is unspecified)
also installing the dependencies ‘sodium’, ‘RSQLite’, ‘keyring’
trying URL 'https://cloud.r-project.org/src/contrib/sodium_1.2.1.tar.gz'
Content type 'application/x-gzip' length 468055 bytes (457 KB)
==================================================
downloaded 457 KB
trying URL 'https://cloud.r-project.org/src/contrib/RSQLite_2.2.20.tar.gz'
Content type 'application/x-gzip' length 3745301 bytes (3.6 MB)
==================================================
downloaded 3.6 MB
trying URL 'https://cloud.r-project.org/src/contrib/keyring_1.3.1.tar.gz'
Content type 'application/x-gzip' length 45779 bytes (44 KB)
==================================================
downloaded 44 KB
trying URL 'https://cloud.r-project.org/src/contrib/shinymanager_1.0.410.tar.gz'
Content type 'application/x-gzip' length 2191864 bytes (2.1 MB)
==================================================
downloaded 2.1 MB
* installing *source* package ‘sodium’ ...
** package ‘sodium’ successfully unpacked and MD5 sums checked
** using staged installation
Package libsodium was not found in the pkg-config search path.
Perhaps you should add the directory containing `libsodium.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libsodium' found
Using PKG_CFLAGS=
Using PKG_LIBS=-lsodium
--------------------------- [ANTICONF] --------------------------------
Configuration failed because libsodium was not found. Try installing:
* deb: libsodium-dev (Debian, Ubuntu, etc)
* rpm: libsodium-devel (Fedora, EPEL)
* csw: libsodium_dev (Solaris)
* brew: libsodium (OSX)
If libsodium is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libsodium.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
-------------------------- [ERROR MESSAGE] ---------------------------
<stdin>:1:10: fatal error: sodium.h: No such file or directory
compilation terminated.
--------------------------------------------------------------------
ERROR: configuration failed for package ‘sodium’
* removing ‘/root/R/x86_64-pc-linux-gnu-library/4.1/sodium’
* installing *source* package ‘RSQLite’ ...
** package ‘RSQLite’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
###### Various Download info #########
The downloaded source packages are in
‘/tmp/Rtmp9w5Zc6/downloaded_packages’
Warning messages:
1: In install.packages("shinymanager", dependencies = T) :
installation of package ‘sodium’ had non-zero exit status
2: In install.packages("shinymanager", dependencies = T) :
installation of package ‘keyring’ had non-zero exit status
UPDATE
Inerestingly I was able to get shinymanager to download how ever I believe the LibPath is inccorrect. I believe I need to change it from /root/R/x86_64-pc-linux-gnu-library/4.1 to /usr/local/lib/R/site-library
I wish I could give the exact solution but I am sure why it finally worked. I tried various install.packages() specifying libpath and dependencies. I then ran into the same issue with RSQLite and that worked eventually too after it failing for many tries and combinations.

R cannot download websockets package from the github

The manual is written here:https://github.com/Refinitiv/websocket-api/tree/master/Applications/Examples/R
The mentioned code is written in Section 2 of Install libraries
Problems are with this part
library(devtools)
install_github("brettjbush/R-Websockets")
With R and RTools versions above 4.0 I have following error.
> install_github("brettjbush/R-Websockets")
Downloading GitHub repo brettjbush/R-Websockets#HEAD
Installing 1 packages: caTools
Installing package into ‘\\energia.sise/dfs/REDIRECT/german.suhharukov/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.0/caTools_1.18.0.zip'
Content type 'application/zip' length 317292 bytes (309 KB)
downloaded 309 KB
package ‘caTools’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\german.suhharukov\AppData\Local\Temp\RtmpoRYGc0\downloaded_packages
√ checking for file 'C:\Users\german.suhharukov\AppData\Local\Temp\RtmpoRYGc0\remotes1aa03e212c08\brettjbush-R-Websockets-fc7ee9c/DESCRIPTION' (1s)
- preparing 'websockets':
√ checking DESCRIPTION meta-information ...
- cleaning src
Warning in system2(command, args, stdout = NULL, stderr = NULL, ...) :
'CreateProcess' failed to run 'C:\rtools40\usr\bin\make.exe -f "C:/PROGRA~1/R/R-40~1.3/share/make/clean.mk" -f Makevars.win clean'
- checking for LF line-endings in source and make files and shell scripts
- checking for empty or unneeded directories
- building 'websockets_1.1.7.tar.gz'
Installing package into ‘\\sise/dfs/REDIRECT/MYNAME/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
'\\sise\dfs\REDIRECT\MYNAME\Documents'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
* installing *source* package 'websockets' ...
** using staged installation
** libs
*** arch - i386
Error in system(cmd) :
(converted from warning) 'CreateProcess' failed to run 'C:\rtools40\usr\bin\make.exe -f "Makevars.win" -f "C:/PROGRA~1/R/R-40~1.3/etc/i386/Makeconf" -f "C:/PROGRA~1/R/R-40~1.3/share/make/winshlib.mk" SHLIB="websockets.dll" OBJECTS="libsock.o"'
* removing '\\sise/dfs/REDIRECT/MYNAME/Documents/R/win-library/4.0/websockets'
Error: Failed to install 'websockets' from GitHub:
(converted from warning) installation of package ‘C:/Users/MYNAME/AppData/Local/Temp/RtmpoRYGc0/file1aa0518554ea/websockets_1.1.7.tar.gz’ had non-zero exit status
> install.packages("caTools")
Installing package into ‘\\sise/dfs/REDIRECT/MYNAME/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.0/caTools_1.18.0.zip'
Content type 'application/zip' length 317292 bytes (309 KB)
downloaded 309 KB
package ‘caTools’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\MYNAME\AppData\Local\Temp\XXXXXXX\downloaded_packages
>
Errors are following
> library(devtools)
Loading required package: usethis
> install_github("brettjbush/R-Websockets")
Downloading GitHub repo brettjbush/R-Websockets#master
trying URL 'https://cran.rstudio.com/bin/windows/Rtools/Rtools35.exe'
Content type 'application/x-msdownload' length 108622512 bytes (103.6 MB)
downloaded 103.6 MB
Error: Failed to install 'websockets' from GitHub:
Could not find tools necessary to compile a package
Call `pkgbuild::check_build_tools(debug = TRUE)` to diagnose the problem.
> pkgbuild::check_build_tools(debug = TRUE)
trying URL 'https://cran.rstudio.com/bin/windows/Rtools/Rtools35.exe'
Content type 'application/x-msdownload' length 108622512 bytes (103.6 MB)
downloaded 103.6 MB
Error: Could not find tools necessary to compile a package
Call `pkgbuild::check_build_tools(debug = TRUE)` to diagnose the problem.
> find_rtools()
[1] TRUE
> Sys.which("ls.exe")
ls.exe
"C:\\Rtools\\bin\\ls.exe"
How can I download this package?
In the notes on github it says "NOTE: This package is no longer maintained. For implementing websocket servers in R, try the httpuv package"
Another possible problem could be that you are running a new version of R with an old version of Rtools. So I'd try to install the newest version of Rtools or run an older version of R with a compatible version of Rtools, such that you can build and compile the package.
I ran your code on my machine running R 4.0.2 and Rtools 4.0.0 and did not face any issues installing the package. So I'd suggest installinng the newest version of R and Rtools from here: https://cran.r-project.org/bin/windows/Rtools/ and trying again.

Problem getting R installed as kernel in Jupyter Notebook

I'm trying to get R installed as a kernel for jupyter notebook. I am follwing the instructions at: https://irkernel.github.io/installation/ but when I try to install IRkernel I get:
also installing the dependency 'uuid'
trying URL 'https://cran.mtu.edu/src/contrib/uuid_0.1-4.tar.gz'
Content type 'application/x-gzip' length 49544 bytes (48 KB)
==================================================
downloaded 48 KB
trying URL 'https://cran.mtu.edu/src/contrib/IRkernel_1.1.tar.gz'
Content type 'application/x-gzip' length 52805 bytes (51 KB)
==================================================
downloaded 51 KB
* installing *source* package 'uuid' ...
** package 'uuid' successfully unpacked and MD5 sums checked
** using staged installation
checking for gcc... x86_64-apple-darwin13.4.0-clang
checking whether the C compiler works... no
configure: error: in `/private/var/folders/y2/38gkkc0s7d52_mr_s6zfj7m80000gq/T/Rtmpru6fsM/R.INSTALL92f935860c3f/uuid':
configure: error: C compiler cannot create executables
See `config.log' for more details
ERROR: configuration failed for package 'uuid'
* removing '/anaconda3/lib/R/library/uuid'
ERROR: dependency 'uuid' is not available for package 'IRkernel'
* removing '/anaconda3/lib/R/library/IRkernel'
The downloaded source packages are in
'/private/var/folders/y2/38gkkc0s7d52_mr_s6zfj7m80000gq/T/Rtmpg79DeD/downloaded_packages'
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
Warning messages:
1: In install.packages("IRkernel") :
installation of package 'uuid' had non-zero exit status
2: In install.packages("IRkernel") :
installation of package 'IRkernel' had non-zero exit status
Can someone please tell me the problem?emphasized text

R can't find path for sh

Having a critical issue installing packages in R (I'm on Mac OS). I tried installing a package (below) using Rstudio:
> install.packages("igraph")
Installing package into ‘/usr/local/lib/R/3.6/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/igraph_1.2.4.1.tar.gz'
Content type 'application/x-gzip' length 2704004 bytes (2.6 MB)
==================================================
downloaded 2.6 MB
* installing *source* package ‘igraph’ ...
** package ‘igraph’ successfully unpacked and MD5 sums checked
** using staged installation
./configure: line 473: sed: command not found
./configure: line 472: expr: command not found
./configure: line 473: sed: command not found
./configure: line 487: sed: command not found
: error: cannot create .lineno; rerun with a POSIX shell
ERROR: configuration failed for package ‘igraph’
* removing ‘/usr/local/lib/R/3.6/site-library/igraph’
sh: rm: command not found
Warning in install.packages :
installation of package ‘igraph’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/ll/jmydhb6n7jqg5rv_c58jxkkh0000gn/T/Rtmpi1rAL3/downloaded_packages’
I then tried it in R console:
> install.packages("igraph")
Installing package into ‘/usr/local/lib/R/3.6/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.ma.imperial.ac.uk/src/contrib/igraph_1.2.4.1.tar.gz'
Content type 'application/x-gzip' length 2704004 bytes (2.6 MB)
==================================================
downloaded 2.6 MB
/usr/local/Cellar/r/3.6.1/lib/R/bin/R: line 143: exec: sh: not found
The downloaded source packages are in
‘/private/var/folders/ll/jmydhb6n7jqg5rv_c58jxkkh0000gn/T/Rtmpq31bYd/downloaded_packages’
Warning messages:
1: In system2(cmd0, args, env = env, stdout = outfile, stderr = outfile, :
error in running command
2: In install.packages("igraph") :
installation of package ‘igraph’ had non-zero exit status
I'm guessing the issue is related to one of my PATH variables. I also tried installing the most recent version of xcode to no avail. Below are the details I can get on my various PATHs:
From Rstudio:
Sys.getenv("PATH")
[1] "/Users/gordon.beattie/.virtualenvs/r-reticulate/bin:/Users/gordon.beattie/.virtualenvs/r-reticulate/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/gordon.beattie/Downloads/R_packages/gliph-master/gliph/bin"
From R console
> Sys.getenv("PATH")
[1] "/usr/local/bin"
From .Renviron
R_LIBS=~/R/library
PAGER=/usr/local/bin/less
PATH=/Users/gordon.beattie/Downloads/R_packages/gliph-master/gliph/bin
PATH=/usr/local/bin
PATH=/usr/local/bin
PATH=/usr/bin
PATH=/bin
PATH=/usr/sbin
PATH=/sbin
PATH=/Users/gordon.beattie/.virtualenvs/r-reticulate/bin
PATH=/Users/gordon.beattie/.virtualenvs/r-reticulate/bin
PATH=/usr/bin:/bin:/usr/sbin
PATH=/sbin
PATH=/usr/local/bin
My system PATH
echo $PATH
/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Additional info:
echo $0
-bash
echo $SHELL
/bin/bash
which sh
/bin/sh

install.packages() having issues with setwd()

I'm attempting to install a package in R (v3.4 on Linux (64-bit)) and am being told that the execution was halted.
I attempted to log out of R and clear out my History and Environment. Below is the cod and the output I am getting:
> install.packages('zip')
Installing package into ‘/home/clang/R/x86_64-redhat-linux-gnu-library/3.4’ (as ‘lib’ is
unspecified) trying URL
'http://cran.rstudio.com/src/contrib/zip_1.0.0.tar.gz' Content type
'application/x-gzip' length 60823 bytes (59 KB)
================================================== downloaded 59 KB
Error: 1:7: unexpected '/' 1: setwd(/
^ Execution halted Warning in install.packages : installation of package ‘zip’ had non-zero exit status
The downloaded source packages are in
‘/tmp/RtmpaFlNP9/downloaded_packages’

Resources