I have a .Rmd file with the following content
```{r, cache=FALSE}
x <- rnorm(10)
plot(x)
```
and running it in RStudio gives the output
If I save the file, close RStudio and open the file again, the output is still there despite the cache=FALSE setting. How can I deactivate that the plot, or chunk output in general, is cached and not displayed If the .Rmd file is opened the next time? Where is this cache stored on my system?
Related
When I pull in data from a csv:
descriptions <- read.csv("descriptions.csv")
on a Windows machine, and use outputText
output$textDesc <- renderText({ descriptions[1,1] })
The output shows a "1".
When I use the same code on a Mac, I get the data that is in descriptions[1,1] which is a string of information that I want displayed.
How can I get the text in descriptions[1,1] to show up on the Windows machine?
I am working in RStudio (on a Mac) to write reports which are rendered as PDF.
I am working in an English locale.
The report, however, is in German and I would like to use German decimal and group (thousands) marks in the report without changing the locale of the OS (or R).
I would like to do this by setting one global option at the beginning of the Rmd file.
Is there a way to accomplish this?
Up until now I tried
command line in Terminal
defaults write org.R-project.R force.LANG de_AT.UTF-8
This only changed the UI language used by R itself, no by RStudio.
Sys.setlocale("LC_NUMERIC","de_DE")
in an Rmd document produces
Error: package or namespace load failed for ’sf': .onLoad failed in loadNamespace() for ’units’, details: call:
udunits_initCfile.path(.get_ud_xml_dir(), "udunits2.xml")) error: Error in function udunits.init: Can't open
installed, default, unit database Execution halted
Putting
NUMERIC="de_DE"
LC_NUMERIC="de_DE"
in .Renviron does not help either
Quoting ?locales
Setting "LC_NUMERIC" to any value other than "C" may cause R to function anomalously, so gives a warning. Input conversions in R itself are unaffected, but the reading and writing of ASCII save files will be, as may packages which do their own input/output.
Setting it temporarily on a Unix-alike to produce graphical or text output may work well enough, but options(OutDec) is often preferable.
So let's try that:
---
output: pdf_document
lang: de-DE
---
```{r echo=FALSE}
options(OutDec = ",")
library(sf)
knitr::kable(head(mtcars))
```
Dies ist ein nichtssagender Blindtext inklusive R output `r pi` der genau so
lang ist, dass es zu Zeilenumbrüchen mit Trennung kommt.
Result:
Notes:
There is no group-separator, since R does not use that in its output.
I have added lang: de-DE to enable German hyphenation patterns.
Loading the sf package works without problems.
I would like to end an Rmd file with the render() command to create an (in my case) Word document of the finished report. The reason I'm using the command render() instead of the Knit button is to manipulate where it stores my output file.
If I have the line render(file.Rmd) in my the same Rmd that I'm trying to render I get two errors.
If I have named chunks, the first error that it will print is:
Error in parse_block(g[-1], g[1], params.src) : duplicate label 'setup'
If I do not have named chunks, it goes through the loop of rendering over and over again and gives me the error:
Error in sink(con, split = debug) : sink stack is full
What I understand now is that when the call is made in the same Rmd, the process will recursively analyze the Rmd over and over again.
So, how do you call render() if it can't be in your file?
My solution as of now is to comment out the render command, save the file, uncomment it, and then run it. But this seems awfully clunky.
Thanks for your input!
I would like to run LIWC (installed in my Mac) within a python 2.7 script.
I have been reading about subprocess (popen and check_output seem the way to go), but I do not get the syntax for:
opening the program;
getting a text file to be analysed;
running the program;
getting the output (analysis) and storing it in a text file.
This is my first approach to subprocess, is this possible?
I appreciate the suggestions.
EDIT
This is the closest to implementing a solution (still does not work):
I can open the application.
subprocess.call(['open', '/file.app'])
But cannot make it process the input file and get an output one.
subprocess.Popen(['/file.app', '-input', 'input.txt', '-output', 'output.txt'])
Nothing comes out of this code.
EDIT 2
After reading dozens of posts, I am still very confused about the syntax for the solution.
Following How do I pipe a subprocess call to a text file?
I came out with this code:
g = open('in_file.txt', 'rb', 0)
f = open('out_file.txt', 'wb')
subprocess.call(['open', "file.app"] stdin=g, stdout=f)
The output file comes out empty.
EDIT 3
Following http://www.cplusplus.com/forum/unices/40680/
When I run the following shell script on the Terminal:
cat input.txt | /Path/LIWC > output.txt
The output txt file is empty.
EDIT 4
When I run:
subprocess.check_call(['/PATH/LIWC', 'PATH/input.txt', 'PATH/output.txt'])
It opens LIWC, does not create an output file and freezes.
EDIT 5
When I run:
subprocess.call(['/PATH/LIWC', 'PATH/input.txt', 'PATH/output.txt'])
It runs LIWC, creates an empty output.txt file and freezes (the process does not end).
The problem with using 'open' in subprocess.call(['open', "file.app"] stdin=g, stdout=f) is that it requests that a file be opened through a service, and doesn't directly attach it to your python process. You'll need to instead use the path to LIWC. I'm not sure that it supports reading from stdin, though, so you might need to even pass in the path to the file you'd like it to open.
I have a script (called: anim.sh) to read in my simulation data, plot each data file in gnuplot, and save each as a .gif file. The data is named: g000000, g000007, g000008, g000010....etc. My script reads in these 4 data files and makes a plot in gnuplot, then saves the output as a .gif file. My question is how do I read in this irregularly numbered data? I have:
do for [i=0:3] {
str_num=sprintf('%03d',i) #Write integer to string
set term gif
set output 'my_output.'.str_num.'.gif'
set xr [-0.2:0.2]
set yr [-0.2:0.2]
plot 'g000'.str_num w d
}
This would work fine if my files were called g000000, g000001, g000002, g000003 but they are not! so I get an error:
line 8: warning: Skipping unreadable file "g000001"
line 8: No data in plot
How do I add to the code to skip missing files (e.g. g000001 - g000006) and continue the loop?
p.s. In reality i have hundreds of files and not just 4 so I don't want to rename them by hand.
You can generate a list of all files and iterate over them:
set terminal gif
set xrange[-0.2:0.2]
set yrange[-0.2:0.2]
filelist = system('ls g00*')
do for [file in filelist] {
set output 'my_output.'.(file[2:*]).'.gif'
plot file
}