R-code linebreaks AND themes in knitrR-code linebreaks AND code highlighting in knitrR-code linebreaks AND...
Pinhole Camera with Instant Film
PTIJ: Who should pay for Uber rides: the child or the parent?
How to deal with taxi scam when on vacation?
Is it possible that AIC = BIC?
Schematic conventions for different supply rails
Can hydraulic brake levers get hot when brakes overheat?
Official degrees of earth’s rotation per day
Using "wallow" verb with object
What options are left, if Britain cannot decide?
Identifying the interval from A♭ to D♯
How is the Swiss post e-voting system supposed to work, and how was it wrong?
RegionDifference for Cylinder and Cuboid
Why are the outputs of printf and std::cout different
Why must traveling waves have the same amplitude to form a standing wave?
An Accountant Seeks the Help of a Mathematician
In-house repeater?
Employee lack of ownership
SQL Server Primary Login Restrictions
Why is "das Weib" grammatically neuter?
Why does Deadpool say "You're welcome, Canada," after shooting Ryan Reynolds in the end credits?
Counting certain elements in lists
Rejected in 4th interview round citing insufficient years of experience
My adviser wants to be the first author
What are the possible solutions of the given equation?
R-code linebreaks AND themes in knitr
R-code linebreaks AND code highlighting in knitrR-code linebreaks AND code highlighting in knitrMore sophisticated syntax highlighting of Prolog codeHow to get listings that both feature line breaking of long identifiers and keywords highlighting?Knitr/LaTeX: conditional execution based on external parametersDifferent colors for default and language-specific listingsknitr in RStudio produces 'Undefined control sequence', alongside other issuesR data.table and knitrHow does knitr inject TeX code into the document?Latex code in knitr script?Using knitr and Latex problem
hpesoj626 provides two great minimal working examples for how to get R-code linebreaks AND code highlighting in knitr. I was wondering if it was possible to use Yihui's knitr themes within either of the two examples? And if so, how?
Here is the code for the example that I personally prefer (I added language=R and the three lines between hashtags in the setup chunk, and deleted highlight = FALSE in the chunk in the document):
documentclass[twocolumn]{article}
usepackage{listings}
usepackage{inconsolata}
lstset{breaklines=true,showstringspaces=false,language=R}
<<setup, include=FALSE, cache=FALSE>>=
opts_chunk$set(fig.path = 'figure/listings-')
options(replace.assign = TRUE, width=60)
render_listings()
################################################
# not part of hpesoj626's example and not working:
opts_chunk$set(fig.path = 'figure/listings-')
opts_knit$set( out.format="latex" )
################################################
@
title{Function listings with linebreaks and code highlighting}
begin{document}
maketitle
Two ways of printing the code.
<<tidy=TRUE>>=
theFunction <- function(x) {
tmp <- "A really long string that should be line-broken but it would be nice to also see code highlighting colors. The function is in the real code sourced, but for the sake of easier reproducibility, it is written here instead."
}
theFunction
@
end{document}
I was wondering if it was possible to integrate knitr themes into this minimal working example, similar to what Michael suggested here:
opts_knit$set( out.format="latex" )
knit_theme$set("print")
Adding these two lines to the minimal working example above does not do anything (when I delete all other options in the setup chunk and only include these two lines, syntax highlighting works fine).
Alternatively, if adding themes does not work, is it possible to redefine the default listings style such that it exactly resembles a theme (similar to what hpesoj626 suggested in his first answer, but then with R syntax highlighting of all keywords, numbers, commas...)? I tried writing down all definitions based on Carsten Heinz' drivers manual for the listings package (lstdrvs.pdf here) but did not manage.
line-breaking highlighting r knitr
bumped to the homepage by Community♦ 1 min ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
hpesoj626 provides two great minimal working examples for how to get R-code linebreaks AND code highlighting in knitr. I was wondering if it was possible to use Yihui's knitr themes within either of the two examples? And if so, how?
Here is the code for the example that I personally prefer (I added language=R and the three lines between hashtags in the setup chunk, and deleted highlight = FALSE in the chunk in the document):
documentclass[twocolumn]{article}
usepackage{listings}
usepackage{inconsolata}
lstset{breaklines=true,showstringspaces=false,language=R}
<<setup, include=FALSE, cache=FALSE>>=
opts_chunk$set(fig.path = 'figure/listings-')
options(replace.assign = TRUE, width=60)
render_listings()
################################################
# not part of hpesoj626's example and not working:
opts_chunk$set(fig.path = 'figure/listings-')
opts_knit$set( out.format="latex" )
################################################
@
title{Function listings with linebreaks and code highlighting}
begin{document}
maketitle
Two ways of printing the code.
<<tidy=TRUE>>=
theFunction <- function(x) {
tmp <- "A really long string that should be line-broken but it would be nice to also see code highlighting colors. The function is in the real code sourced, but for the sake of easier reproducibility, it is written here instead."
}
theFunction
@
end{document}
I was wondering if it was possible to integrate knitr themes into this minimal working example, similar to what Michael suggested here:
opts_knit$set( out.format="latex" )
knit_theme$set("print")
Adding these two lines to the minimal working example above does not do anything (when I delete all other options in the setup chunk and only include these two lines, syntax highlighting works fine).
Alternatively, if adding themes does not work, is it possible to redefine the default listings style such that it exactly resembles a theme (similar to what hpesoj626 suggested in his first answer, but then with R syntax highlighting of all keywords, numbers, commas...)? I tried writing down all definitions based on Carsten Heinz' drivers manual for the listings package (lstdrvs.pdf here) but did not manage.
line-breaking highlighting r knitr
bumped to the homepage by Community♦ 1 min ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
hpesoj626 provides two great minimal working examples for how to get R-code linebreaks AND code highlighting in knitr. I was wondering if it was possible to use Yihui's knitr themes within either of the two examples? And if so, how?
Here is the code for the example that I personally prefer (I added language=R and the three lines between hashtags in the setup chunk, and deleted highlight = FALSE in the chunk in the document):
documentclass[twocolumn]{article}
usepackage{listings}
usepackage{inconsolata}
lstset{breaklines=true,showstringspaces=false,language=R}
<<setup, include=FALSE, cache=FALSE>>=
opts_chunk$set(fig.path = 'figure/listings-')
options(replace.assign = TRUE, width=60)
render_listings()
################################################
# not part of hpesoj626's example and not working:
opts_chunk$set(fig.path = 'figure/listings-')
opts_knit$set( out.format="latex" )
################################################
@
title{Function listings with linebreaks and code highlighting}
begin{document}
maketitle
Two ways of printing the code.
<<tidy=TRUE>>=
theFunction <- function(x) {
tmp <- "A really long string that should be line-broken but it would be nice to also see code highlighting colors. The function is in the real code sourced, but for the sake of easier reproducibility, it is written here instead."
}
theFunction
@
end{document}
I was wondering if it was possible to integrate knitr themes into this minimal working example, similar to what Michael suggested here:
opts_knit$set( out.format="latex" )
knit_theme$set("print")
Adding these two lines to the minimal working example above does not do anything (when I delete all other options in the setup chunk and only include these two lines, syntax highlighting works fine).
Alternatively, if adding themes does not work, is it possible to redefine the default listings style such that it exactly resembles a theme (similar to what hpesoj626 suggested in his first answer, but then with R syntax highlighting of all keywords, numbers, commas...)? I tried writing down all definitions based on Carsten Heinz' drivers manual for the listings package (lstdrvs.pdf here) but did not manage.
line-breaking highlighting r knitr
hpesoj626 provides two great minimal working examples for how to get R-code linebreaks AND code highlighting in knitr. I was wondering if it was possible to use Yihui's knitr themes within either of the two examples? And if so, how?
Here is the code for the example that I personally prefer (I added language=R and the three lines between hashtags in the setup chunk, and deleted highlight = FALSE in the chunk in the document):
documentclass[twocolumn]{article}
usepackage{listings}
usepackage{inconsolata}
lstset{breaklines=true,showstringspaces=false,language=R}
<<setup, include=FALSE, cache=FALSE>>=
opts_chunk$set(fig.path = 'figure/listings-')
options(replace.assign = TRUE, width=60)
render_listings()
################################################
# not part of hpesoj626's example and not working:
opts_chunk$set(fig.path = 'figure/listings-')
opts_knit$set( out.format="latex" )
################################################
@
title{Function listings with linebreaks and code highlighting}
begin{document}
maketitle
Two ways of printing the code.
<<tidy=TRUE>>=
theFunction <- function(x) {
tmp <- "A really long string that should be line-broken but it would be nice to also see code highlighting colors. The function is in the real code sourced, but for the sake of easier reproducibility, it is written here instead."
}
theFunction
@
end{document}
I was wondering if it was possible to integrate knitr themes into this minimal working example, similar to what Michael suggested here:
opts_knit$set( out.format="latex" )
knit_theme$set("print")
Adding these two lines to the minimal working example above does not do anything (when I delete all other options in the setup chunk and only include these two lines, syntax highlighting works fine).
Alternatively, if adding themes does not work, is it possible to redefine the default listings style such that it exactly resembles a theme (similar to what hpesoj626 suggested in his first answer, but then with R syntax highlighting of all keywords, numbers, commas...)? I tried writing down all definitions based on Carsten Heinz' drivers manual for the listings package (lstdrvs.pdf here) but did not manage.
line-breaking highlighting r knitr
line-breaking highlighting r knitr
edited Feb 12 at 23:06
Flo
asked Apr 13 '15 at 9:27
FloFlo
1536
1536
bumped to the homepage by Community♦ 1 min ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 1 min ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I was able to get themes working as follows:
<<echo=FALSE>>=
knit_theme$set("biogoo")
@
<<results='asis', echo=FALSE>>=
x <-1:10
y <- x^2
@
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f238331%2fr-code-linebreaks-and-themes-in-knitr%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I was able to get themes working as follows:
<<echo=FALSE>>=
knit_theme$set("biogoo")
@
<<results='asis', echo=FALSE>>=
x <-1:10
y <- x^2
@
add a comment |
I was able to get themes working as follows:
<<echo=FALSE>>=
knit_theme$set("biogoo")
@
<<results='asis', echo=FALSE>>=
x <-1:10
y <- x^2
@
add a comment |
I was able to get themes working as follows:
<<echo=FALSE>>=
knit_theme$set("biogoo")
@
<<results='asis', echo=FALSE>>=
x <-1:10
y <- x^2
@
I was able to get themes working as follows:
<<echo=FALSE>>=
knit_theme$set("biogoo")
@
<<results='asis', echo=FALSE>>=
x <-1:10
y <- x^2
@
answered Feb 12 at 22:51
StatsStudentStatsStudent
15116
15116
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f238331%2fr-code-linebreaks-and-themes-in-knitr%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown