r markdown, knitr and latex symbols
up vote
1
down vote
favorite
After several hours of searching for an answer to no avail, I thought I'd seek advice here.
I'm trying to produce some very simple html tables using knitr in r markdown, but I can't get the latex symbols to display correctly in the column names.
Example code, with several different symbols:
kable(data.frame("$^3$" = "a",
"$\epsilon^2$" = "b",
"$%$" = "c"),
escape = F)
As you can see the column names are not formatted X..3.
X..epsilon.2.
X...
Any help would be much appreciated
r latex r-markdown knitr
add a comment |
up vote
1
down vote
favorite
After several hours of searching for an answer to no avail, I thought I'd seek advice here.
I'm trying to produce some very simple html tables using knitr in r markdown, but I can't get the latex symbols to display correctly in the column names.
Example code, with several different symbols:
kable(data.frame("$^3$" = "a",
"$\epsilon^2$" = "b",
"$%$" = "c"),
escape = F)
As you can see the column names are not formatted X..3.
X..epsilon.2.
X...
Any help would be much appreciated
r latex r-markdown knitr
which packages are using to achieve this?
– sai saran
Nov 12 at 5:29
1
knitr and base r
– Mr. Me
Nov 12 at 23:21
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
After several hours of searching for an answer to no avail, I thought I'd seek advice here.
I'm trying to produce some very simple html tables using knitr in r markdown, but I can't get the latex symbols to display correctly in the column names.
Example code, with several different symbols:
kable(data.frame("$^3$" = "a",
"$\epsilon^2$" = "b",
"$%$" = "c"),
escape = F)
As you can see the column names are not formatted X..3.
X..epsilon.2.
X...
Any help would be much appreciated
r latex r-markdown knitr
After several hours of searching for an answer to no avail, I thought I'd seek advice here.
I'm trying to produce some very simple html tables using knitr in r markdown, but I can't get the latex symbols to display correctly in the column names.
Example code, with several different symbols:
kable(data.frame("$^3$" = "a",
"$\epsilon^2$" = "b",
"$%$" = "c"),
escape = F)
As you can see the column names are not formatted X..3.
X..epsilon.2.
X...
Any help would be much appreciated
r latex r-markdown knitr
r latex r-markdown knitr
edited Nov 12 at 8:27
kath
3,800724
3,800724
asked Nov 12 at 3:17
Mr. Me
103
103
which packages are using to achieve this?
– sai saran
Nov 12 at 5:29
1
knitr and base r
– Mr. Me
Nov 12 at 23:21
add a comment |
which packages are using to achieve this?
– sai saran
Nov 12 at 5:29
1
knitr and base r
– Mr. Me
Nov 12 at 23:21
which packages are using to achieve this?
– sai saran
Nov 12 at 5:29
which packages are using to achieve this?
– sai saran
Nov 12 at 5:29
1
1
knitr and base r
– Mr. Me
Nov 12 at 23:21
knitr and base r
– Mr. Me
Nov 12 at 23:21
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
You can use those column names in a data frame, but you need to tell the data.frame
function not to mangle them using check.names = FALSE
.
However, this isn't enough to fix your example, because $%$
is not legal LaTeX.
You need to escape the percent sign or it will be taken to be a comment character.
So this works:
my_data <- data.frame("$^3$" = "a",
"$\epsilon^2$" = "b",
"$\%$" = "c",
check.names = FALSE)
kable(my_data)
Thanks so much! This fixed my issue!!!
– Mr. Me
Nov 12 at 20:23
add a comment |
up vote
2
down vote
You can set the col.names
in your kable
-call. It does not work in your data.frame
-call, because that does not allow column names which don't start with a dot or letter.
You can see this here:
my_data <- data.frame("$^3$" = "a",
"$\epsilon^2$" = "b",
"$%$" = "c")
my_data
X..3. X..epsilon.2. X...
1 a b c
The solution is:
kable(my_data, escape = F,
col.names = c("$^3$", "$\epsilon^2$", "$%$"))
You might want to use varepsilon
instead of epsilon
as this gives a prettier epsilon (in my opinion).
kable(my_data, escape = F,
col.names = c("$^3$", "$\varepsilon^2$", "$%$"))
Thank you! I wasn't aware the data frame caused these kind of issues. Cheers for the varepsilon tip too!
– Mr. Me
Nov 12 at 20:24
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f53255541%2fr-markdown-knitr-and-latex-symbols%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You can use those column names in a data frame, but you need to tell the data.frame
function not to mangle them using check.names = FALSE
.
However, this isn't enough to fix your example, because $%$
is not legal LaTeX.
You need to escape the percent sign or it will be taken to be a comment character.
So this works:
my_data <- data.frame("$^3$" = "a",
"$\epsilon^2$" = "b",
"$\%$" = "c",
check.names = FALSE)
kable(my_data)
Thanks so much! This fixed my issue!!!
– Mr. Me
Nov 12 at 20:23
add a comment |
up vote
1
down vote
accepted
You can use those column names in a data frame, but you need to tell the data.frame
function not to mangle them using check.names = FALSE
.
However, this isn't enough to fix your example, because $%$
is not legal LaTeX.
You need to escape the percent sign or it will be taken to be a comment character.
So this works:
my_data <- data.frame("$^3$" = "a",
"$\epsilon^2$" = "b",
"$\%$" = "c",
check.names = FALSE)
kable(my_data)
Thanks so much! This fixed my issue!!!
– Mr. Me
Nov 12 at 20:23
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You can use those column names in a data frame, but you need to tell the data.frame
function not to mangle them using check.names = FALSE
.
However, this isn't enough to fix your example, because $%$
is not legal LaTeX.
You need to escape the percent sign or it will be taken to be a comment character.
So this works:
my_data <- data.frame("$^3$" = "a",
"$\epsilon^2$" = "b",
"$\%$" = "c",
check.names = FALSE)
kable(my_data)
You can use those column names in a data frame, but you need to tell the data.frame
function not to mangle them using check.names = FALSE
.
However, this isn't enough to fix your example, because $%$
is not legal LaTeX.
You need to escape the percent sign or it will be taken to be a comment character.
So this works:
my_data <- data.frame("$^3$" = "a",
"$\epsilon^2$" = "b",
"$\%$" = "c",
check.names = FALSE)
kable(my_data)
answered Nov 12 at 13:47
user2554330
8,76311237
8,76311237
Thanks so much! This fixed my issue!!!
– Mr. Me
Nov 12 at 20:23
add a comment |
Thanks so much! This fixed my issue!!!
– Mr. Me
Nov 12 at 20:23
Thanks so much! This fixed my issue!!!
– Mr. Me
Nov 12 at 20:23
Thanks so much! This fixed my issue!!!
– Mr. Me
Nov 12 at 20:23
add a comment |
up vote
2
down vote
You can set the col.names
in your kable
-call. It does not work in your data.frame
-call, because that does not allow column names which don't start with a dot or letter.
You can see this here:
my_data <- data.frame("$^3$" = "a",
"$\epsilon^2$" = "b",
"$%$" = "c")
my_data
X..3. X..epsilon.2. X...
1 a b c
The solution is:
kable(my_data, escape = F,
col.names = c("$^3$", "$\epsilon^2$", "$%$"))
You might want to use varepsilon
instead of epsilon
as this gives a prettier epsilon (in my opinion).
kable(my_data, escape = F,
col.names = c("$^3$", "$\varepsilon^2$", "$%$"))
Thank you! I wasn't aware the data frame caused these kind of issues. Cheers for the varepsilon tip too!
– Mr. Me
Nov 12 at 20:24
add a comment |
up vote
2
down vote
You can set the col.names
in your kable
-call. It does not work in your data.frame
-call, because that does not allow column names which don't start with a dot or letter.
You can see this here:
my_data <- data.frame("$^3$" = "a",
"$\epsilon^2$" = "b",
"$%$" = "c")
my_data
X..3. X..epsilon.2. X...
1 a b c
The solution is:
kable(my_data, escape = F,
col.names = c("$^3$", "$\epsilon^2$", "$%$"))
You might want to use varepsilon
instead of epsilon
as this gives a prettier epsilon (in my opinion).
kable(my_data, escape = F,
col.names = c("$^3$", "$\varepsilon^2$", "$%$"))
Thank you! I wasn't aware the data frame caused these kind of issues. Cheers for the varepsilon tip too!
– Mr. Me
Nov 12 at 20:24
add a comment |
up vote
2
down vote
up vote
2
down vote
You can set the col.names
in your kable
-call. It does not work in your data.frame
-call, because that does not allow column names which don't start with a dot or letter.
You can see this here:
my_data <- data.frame("$^3$" = "a",
"$\epsilon^2$" = "b",
"$%$" = "c")
my_data
X..3. X..epsilon.2. X...
1 a b c
The solution is:
kable(my_data, escape = F,
col.names = c("$^3$", "$\epsilon^2$", "$%$"))
You might want to use varepsilon
instead of epsilon
as this gives a prettier epsilon (in my opinion).
kable(my_data, escape = F,
col.names = c("$^3$", "$\varepsilon^2$", "$%$"))
You can set the col.names
in your kable
-call. It does not work in your data.frame
-call, because that does not allow column names which don't start with a dot or letter.
You can see this here:
my_data <- data.frame("$^3$" = "a",
"$\epsilon^2$" = "b",
"$%$" = "c")
my_data
X..3. X..epsilon.2. X...
1 a b c
The solution is:
kable(my_data, escape = F,
col.names = c("$^3$", "$\epsilon^2$", "$%$"))
You might want to use varepsilon
instead of epsilon
as this gives a prettier epsilon (in my opinion).
kable(my_data, escape = F,
col.names = c("$^3$", "$\varepsilon^2$", "$%$"))
answered Nov 12 at 8:27
kath
3,800724
3,800724
Thank you! I wasn't aware the data frame caused these kind of issues. Cheers for the varepsilon tip too!
– Mr. Me
Nov 12 at 20:24
add a comment |
Thank you! I wasn't aware the data frame caused these kind of issues. Cheers for the varepsilon tip too!
– Mr. Me
Nov 12 at 20:24
Thank you! I wasn't aware the data frame caused these kind of issues. Cheers for the varepsilon tip too!
– Mr. Me
Nov 12 at 20:24
Thank you! I wasn't aware the data frame caused these kind of issues. Cheers for the varepsilon tip too!
– Mr. Me
Nov 12 at 20:24
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2fstackoverflow.com%2fquestions%2f53255541%2fr-markdown-knitr-and-latex-symbols%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
which packages are using to achieve this?
– sai saran
Nov 12 at 5:29
1
knitr and base r
– Mr. Me
Nov 12 at 23:21