1

UPDATED Question 1 In the lattest update of KnitR the output is clean as what I expected. Maybe an update was made.

The new output : enter image description here

Before update

I'm trying to get a particular output with Sweave and R code. For now I have this code :

\documentclass[11pt,french]{report}
  \usepackage{babel} %%french
  \usepackage{amsmath,amsfonts,amssymb} %%maths
  \usepackage[utf8]{inputenc}   % LaTeX
  \usepackage[T1]{fontenc}      % LaTeX
  \usepackage[dvipsnames,table,xcdraw]{xcolor}
  %% Background code chunk
  \usepackage{listings}
  \usepackage{color}

  \definecolor{codegreen}{rgb}{0,0.6,0}
  \definecolor{codegray}{rgb}{0.5,0.5,0.5}
  \definecolor{codepurple}{rgb}{0.58,0,0.82}
  \definecolor{backcolour}{rgb}{0.95,0.95,0.92}
 %% background code chunk listing
  \lstset{
    language=R}
\lstdefinestyle{mystyle}{
    backgroundcolor=\color{backcolour},   
    commentstyle=\color{codegreen},
    keywordstyle=\color{magenta},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{codepurple},
    basicstyle=\footnotesize,
    breakatwhitespace=false,         
    breaklines=true,                 
    captionpos=b,                    
    keepspaces=true,                 
    numbers=left,                    
    numbersep=5pt,                  
    showspaces=false,                
    showstringspaces=false,
    showtabs=false,                  
    tabsize=2
}

\lstset{style=mystyle}

witch is coming from this site.

The R code I'm trying to implement is :

%% script R
\begin{lstlisting}[linerange=\\begin\{Sinput\}-\\end\{Sinput\},includerangemarker=false, caption = Code source en R pour l'exemple]
<<eval =FALSE>>=
# dataset
x <- c(2,3,6,9,12); y <- c(2,5,3,6,5)

# Estimations des parametres
reg <- lm(y ~ x)

# Resume de l'estimation
summary(reg)

# Valeurs de Yt
fitted(reg)

# Residus 
residuals(reg)
@
\end{lstlisting}

The output : enter image description here

My questions :

1- How can I get a better output for the ~ symbol ?

2- Is there a way to eval the code without getting and output like this ? enter image description here

  • Could you precise what you mean with "better" (it is very subjective) and how it should look like? – nebi Aug 1 '17 at 18:24
  • Something like the \sim in latex. a Tilde but not in the air. Now it look like a tilde to get over a character. It's the symbol meaning y follow X. – David Beauchemin Aug 2 '17 at 4:07
  • 1
    About question 2: obviously remove eval =FALSE and depending of what you want exactly , add echo=FALSE or results='hide'. – Fran Aug 6 '18 at 21:09
  • @Fran This solved the case. – David Beauchemin Aug 22 '18 at 17:35
0

The solution for question 2.

<<eval = TRUE, echo=FALSE, fig=TRUE, height=4,width=4.5>>=
[...] precedent code
@

The solution is just add echo=false and eval=false for preventing the \begin{Schunk} and other tex command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.