I'm using R in Databricks. R Studio runs fine and executes from the Databricks cluster. I would like to transition from R Studio to notebooks. However, I am repeatedly getting this error when running the simplest R scripts (one-liner assignments) inside notebooks:
Error in writeLines(DB_STREAM_BEACON_STRING_START__, DATABRICKS_STDERRCONNSTREAM__) :
invalid connection
Some(<code style = 'font-size:10p'> </code>)
Figured it out after several hours of research and troubleshooting. This problem arises from Rmarkdown failing to write various types of common Rmarkdown output (most likely viewer output) to stdout. Rather than directly running rmarkdown::render() from the notebook, run R -e 'rmarkdown::render() > out.txt as a shell script in the notebook, redirecting output to a text file.
Related
I'm having trouble running my R script from Excel VBA.
I wanted to create a Button in Excel with a macro that runs an R script but I've tried so many versions and none worked.
My path to R is "C:\Program Files\R\R-4.1.1\bin\Rscript.exe"
The path to my R Script is "\repo\xyz\18320\38293\one\redirected folder\Desktop\test_run\test\Code\sample.R"
How can I create a shell on VBA which actually executes the Script?
Can I maybe execute the script from the command line and then connect the excel macro to the command line? I didnĀ“t manage to find a solution.
I'm trying to write colored output back to the terminal from an R script running in that terminal. I'm working in the Windows Powershell in Rstudio on Windows 10. It seems like the powershell supports colors, but I cannot get my outputs from R to activate the virtual terminal sequences needed to display them. If I use echo in the terminal, I can display the colors the way I want to:
I've tried multiple ways of writing them to the terminal from within an R script, including using the popular crayon package, but none seem to work:
# test.R
library(crayon)
cat("$([char]27)[36mCyan!$([char]27)[37m\n")
cat("$([char]27)[36m", "Cyan!", "$([char]27)[37m", "\n")
cat(green("Green!"),"\
Note that this post addresses the use of color in the RStudio console while I'm trying to get it to work in the terminal, which is separate. Crayon correctly outputs the colors in the console, but you can't execute a script there.
Is there a way to write lines to the terminal so that the virtual terminal sequences will work properly?
I'm trying to compile a knitr script on a timer using LaunchControl (a launchd GUI for scheduling cron-like jobs on OSX).
I have a dispatcher.R script that does this:
#!/Library/Frameworks/R.framework/Resources/Rscript
library("knitr")
setwd("~/somedirectory")
knit2pdf("my_script.Rnw", output= "my_script.tex")
When I run it interactively from in RStudio, my_script.Rnw works great. I get the desired PDF output. However, when launchd runs the dispatcher.R script I get this error:
Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet, :
Running 'texi2dvi' on 'my_script.tex' failed.
Execution halted
The .tex file gets generated, but then it doesn't compile. I a would say it was problem with my LaTeX installation path, but since it works using knit2pdf() I'm not sure. What could be the issue?
Still working on this. Updates:
No .log file gets produced with knit2pdf() via LaunchControl, but I get a .tex file and /figure folder.
I updated MacTex and also tried a minimal example of an empty document and I got the same error about texi2dvi.
When I run knit2pdf("my_script.Rnw", output = "my_script.tex") using LaunchControl and then go back to RStudio and run texi2dvi("my_script.tex", pdf = TRUE), then I get the desired outcome.
The problem reproduces on Sierra and Yosemite
On Sierra there is an additional error about In my_script_latex_pkg("framed", system.file("misc", "framed.sty", package = "knitr")) : unable to find LaTeX package 'framed'; will use a copy from knitr
I tried Sys.setenv(PATH = paste(Sys.getenv("PATH"),"/usr/texbin",sep=":")) and it didn't help.
Running $ Rscript dispatcher.R from the command line works just fine. The PDF compiles.
Running a bash script with Rscript dispatcher.Rin LaunchControl does not work; same error about texi2dvi.
To run a .Rnw file using LaunchControl for task scheduling, create the following files in the same directory. Then, run the *.sh script in the scheduler. Voila! The problem I was encountering in my original post was the LaunchControl doesn't (by default, at least) read ~/.bash_profile, so adding the PATH variable into the .sh script resolves this.
1) Your *.Rnw script
This is any knitr script that you can compile without issue from RStudio.
2) A *.R script
#!/Library/Frameworks/R.framework/Resources/Rscript
library("knitr")
setwd("~/some_directory")
knit2pdf("yourscript.Rnw", output = "yourscript.tex")
3) A *.sh script
Make sure that you have the PATH variable to your LaTeX installation.
#! /bin/bash
PATH="/usr/texbin:${PATH}"
export PATH
Rscript yourscript_dispatcher.R
This solution works on OSX Yosemite 10.10.5 on R version 3.3.2 (2016-10-31).
I have written an R script, which I run from R using the command source("script.r"). It works perfectly.
However, when I try to run the exact same script from command line using either one of the commands: Rcript script.r, R --vanilla < script.r or R CMD BATCH script.r I get the error:
"Error in library(igraph): there is no package called 'igraph'"
If I remove the line from the script and run it without the command library(igraph), then I get the error that function graph.frame.data could not be found, which is a function of igraph.
The script that runs from the Rstudio, does not contain the line library(igraph) and I don't get such an error.
When trying to inform myself about problems of running igraph from a script I have not found any additional information.
Some more information: I am building a graph from multiple files and then doing calculations using the igraph library on that created graph. This is executed within a loop, that goes through all (specific) directories. Output is written out into a file using cat(..).
Thanks for the help in advance.
The igraph library was not installed to the default lib position.
Using the command library("igraph", lib.loc="..igraph.location..") solved the issue.
The library was loaded and the execution of the script proceeded without problems.
Hej,
When I try to call QIIME with a system call from R, i.e
system2("macqiime")
R stops responding. It's no problem with other command line programs though.
can certain programs not be called from R via system2() ?
MacQIIME version:
MacQIIME 1.8.0-20140103
Sourcing MacQIIME environment variables...
This is the same as a normal terminal shell, except your default
python is DIFFERENT (/macqiime/bin/python) and there are other new
QIIME-related things in your PATH.
(note that I am primarily interested to call QIIME from R Markdown with engine = "sh" which fails, too. But I strongly suspect the problems are related)
In my experience, when you call Qiime from unix command line, it usually creates a virtual shell of it`s own to run its commands which is different from regular system commands like ls or mv. I suspect you may not be able to run Qiime from within R unless you emulate that same shell or configuration Qiime requires. I tried to run it from a python script and was not successful.