Trying to display regression outputs in Rmarkdown in Latex - r

Hi all!
I'm currently working on a paper for my university. The task is to run some regressions on a dataset and compile all results in an rmarkdown file. It should be noted that this is my first time working with R, so if the following question is really stupid, I apologize in advance. ;-)
My problem relates to the display of the regression outputs in Rmarkdown. I want to have them in Latex but somehow it won't work.
I tried to replicate this code https://www.r-statistics.com/tag/stargazer/ but when I enter it I get the following output (this happens both in the console and in Rmarkdown):
When I manually enter Latex in the Rmarkdown document with the $ notation, for instance to include formulas, it works just fine so I'm a bit puzzled.
I feel like I'm missing something very obvious but I can't quite put my finger on it. In any event, any help would be greatly appreciated!

Related

Printing an R code and output using knitr

I'm trying to print an R-code and its output. In the past I remember using a function called knit for this. Looking online it seems it may be part of the package knitr (although I seem to remember there being a button in the file dropdown which did the same).
However I can't work out a simple way to use this, and what functions produce a MS Word output.
Just wondering what the simplest way is to print the r-code and output?

Inserting plots inside code chunks in R Markdowns

I'm trying to add a plot to my R Markdown report, however, when I try to knit what I have yet written I found myself with a disastrous error. I have changed a lot of arguments and parameters in order to show the plot on my Markdown.
This is the error I get
I'd like you to help me fix this error so that I can show all the plots I need.
Make sure you've spelled hours correctly. The error suggests you don't have a variable hours in your dataset. Perhaps it ought to be capitalized?

Rmarkdownon Kaggle: Can you spot what's going on?

it's been a few days that im trying to run my Rmd on Kaggle, but it simply doesn't work.
The main reason (I guess) is that, somehow the console is reading the code as an R code, but im sure that I'm using Rmarkdown.
Therefore, the console reads a Text line as a code line, giving me the code error below:
Also, i tried to copy and edit other's people markdown, but i keep getting the same error line.
You can check my code here: https://www.kaggle.com/badluckmath/kernel4c85aae59c/edit/run/39891200
He's working perfectly on my Rstudio.
I'm looking for a huge help here, please!
I've been stuck with this for a week!
If i press the buttom to run code, it will simply give me this error message.
For that, i still don't know the solution. But since this is a premade Rmarkdown and i knew that it works, i simple used the Save (Commit) options and at the end, it worked.

Debugging code in R Markdown

I've been playing a little bit with R Markdown and I really like it, because after each of my analyses I need to write a (Word) report detailing the results. With R Markdown, the code and report are the same document, so it's easy to remember that I chose to perform analysis B at a certain point in the code, because of the results of analysis A before.
However, I'm not able to set breakpoints in R Markdown inside R Studio, and this limits severely the possibility of performing efficient debugging. This implies that in the end I can only use Markdown for very trivial analyses, where the R code is so simple that either I don't have to debug it, or I can debug it manually. It this to be expected, i.e., is it well-known that R Markdown can only be used for simple analyses? Or is there a solution?
You can use browser() in your code to set breakpoints. See https://support.rstudio.com/hc/en-us/articles/205612627-Debugging-with-RStudio#debugging-in-r-markdown-documents
I've find it more useful to write custom functions in a .R and source() it in Markdown. Then, you get the best of both worlds.
You can generate Word and other reports from normal R scripts using knitr::spin in combination with special roxygen2-style comments. Then you can run your script and use breakpoints as normal.
https://rmarkdown.rstudio.com/articles_report_from_r_script.html
There's also a toolbar button in RStudio to do this.

Syntax highlight in R Sweave

I am fairly new to doing report with R Sweave and know the very basic applications of Latex. And I have been asked to produce some statistical reports. The R markdown is great and simple, and by default it has really nice syntax frame and grey background and syntax highlights, however, it is quite limited in terms of other type setting, not really optimal when you want to produce lengthy reports. Then I am switching to use R Sweave in R studio.
I basically want the same after-effect similar to R markdown in the Sweave. What are the easiest ways to do it? I have previously read the following post discussing:
Sweave syntax highlighting in output. And I have tried reading those package pdf, but have no clues what they are talking about, as they seem to assume readers have prior knowledges about the rendering process.
i have checked them out, but I seem to get stuck in making it to work. Can anyone tell me step by step on how to set it up (such as what to include in preamble), if possible can you kindly upload a simple Rnw file with a demonstration?
Thank!
If you use knitr rather than Sweave, you'll get syntax highlighting. It's probably possible to do it in Sweave, but knitr makes it easier.
Go to your Tools | Global Options | Sweave menu (or the similar one in Project Options) in RStudio, and choose to Weave Rnw files using knitr.
The two systems are very similar, but knitr is generally preferable these days.

Resources