r markdown, knitr and latex symbols












1














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)


Here's the output



As you can see the column names are not formatted X..3. X..epsilon.2. X...



Any help would be much appreciated










share|improve this question
























  • 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
















1














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)


Here's the output



As you can see the column names are not formatted X..3. X..epsilon.2. X...



Any help would be much appreciated










share|improve this question
























  • 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














1












1








1


1





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)


Here's the output



As you can see the column names are not formatted X..3. X..epsilon.2. X...



Any help would be much appreciated










share|improve this question















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)


Here's the output



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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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












2 Answers
2






active

oldest

votes


















1














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)


enter image description here






share|improve this answer





















  • Thanks so much! This fixed my issue!!!
    – Mr. Me
    Nov 12 at 20:23



















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$", "$%$"))


enter image description here



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$", "$%$"))


enter image description here






share|improve this answer





















  • 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











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',
autoActivateHeartbeat: false,
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
});


}
});














draft saved

draft discarded


















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









1














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)


enter image description here






share|improve this answer





















  • Thanks so much! This fixed my issue!!!
    – Mr. Me
    Nov 12 at 20:23
















1














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)


enter image description here






share|improve this answer





















  • Thanks so much! This fixed my issue!!!
    – Mr. Me
    Nov 12 at 20:23














1












1








1






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)


enter image description here






share|improve this answer












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)


enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 at 13:47









user2554330

8,88811237




8,88811237












  • 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




Thanks so much! This fixed my issue!!!
– Mr. Me
Nov 12 at 20:23













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$", "$%$"))


enter image description here



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$", "$%$"))


enter image description here






share|improve this answer





















  • 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
















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$", "$%$"))


enter image description here



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$", "$%$"))


enter image description here






share|improve this answer





















  • 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














2












2








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$", "$%$"))


enter image description here



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$", "$%$"))


enter image description here






share|improve this answer












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$", "$%$"))


enter image description here



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$", "$%$"))


enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










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


















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues