Is there a way to generate an R Markdown report by calling that or other R scripts in a VBScript on windows 7?
My goal is for the user to be able to click the VBScript and have the R Markdown file generate so that the user does not have to interact with R.
I am able to run an R script from a VBScript (using Rscript.exe), but when it comes to an R Markdown file, there seems to be an issue with knitting/rendering.
I am able to source the R Markdown file from an R Script and I also used an R script to generate the HTML report using Markdown functions (see here), but if I call either of those from a VBScript, the report is not generated. I know the script is running because I also generate a text file (outside of the R Markdown file) as a test.
B/c I lack Admin rights, I don't believe I can use a batch file, but regardless, I think I would encounter the same issue. Thanks for any help/insight!
Related
Currently, I am working on a project which builds upon existing code from a colleague. Their script was written in Stata, and thus is a .do file. However, the rest of the code in the project was developed using R. Is there a way to run the .do file at the beginning of the R script, in a similar way to the source() function? Further, will there be any additional difficulties in running the .do file in an Rmd, rather than just an R file?
I found one package, RStata, that seems promising, but I would like to compare any other options before going forward with this package.
I have developed a shiny app with some sections which produce some results. There is another section with the option of download, in HTML format, the plots done in the app. When I am in the R environment it works, but it works because i have the shiny app file .R and the R markdown file .Rmd in the same folder. But when I upload the app in the browser, this link between the shiny app and the r markdown is lost. Is there a way to link both so someone without the Rmd document and without even having R Studio downloaded can use the app and download the plots in an HTML?
I am trying to find some option in shinyapps.io (i guess there's the place where they can be linked) but with no success. Thank you.
Edition: I'm trying something like that https://shiny.rstudio.com/gallery/download-knitr-reports.html
But in this example, it doesn't matter where and what is the R Markdown file?
I have solved the problem. Being in the RStudio environment, when one want to publish the app, in the window "Publish to Server", in the box "Publish Files From", there must be the two files, the .R file where the shiny app code is and the .Rmd where the code for the HTML download is.
I'm having trouble with rmarkdown::render() recognizing a .bib file. I've tried putting it in the www file and also the directory from which the app is run with no success. I've had success locally by adding /users/blah/blah/citations.bib but when deploying this workaround it doesn't work (as it shouldn't). I've also looked into this Bibliography not working when rendering a R Markdown document within an R Shiny App, which works great for static htmls produced prior to deploying; however, my case involves the user creating a unique report while deployed and nullifies this option (I think...). Any suggestions would be much appreciated. Thanks.
Before I invest too much time in it I need to know... Do R Markdown Parameterized Reports require an R Studio Connect server?
If they do that's a little outside of my budget and what I want to get into.
I'd like to be able to send out static .html files people can upload their data.csv into, and another .html file will be spit out based off my scripts and R Markdown.
Parametrized Rmarkdown reports are a feature provided by the rmarkdown package (>= version 0.8). They do not require a RStudio Connect Server. However, you will still need a running R process somewhere to render the report based on the provided parameters.
I have a .Rmd which I use to report on data quality in a number of different r projects. It would then split the data to remove subsets with missing data, and interpolate missing results where appropriate. It would do this via a write.csv command to a file path in the form of "./Cleansed_data/"
To make an example
open rstudio
go to the rhs 'project' menu , and select and make a new
project wherever you'd like
go to the lhs 'new script' drop down and
select 'new .Rmd'
change the output to .pdf and hit ok
in the last r
chunk include write.csv(mtcars, file = "mtcars.csv")
hit the 'knit
pdf' button, save the report as "writeFile.Rmd" to your project working directory, and
let it run.
Previously I moved this .Rmd from place to place, however now I would like to built it into an internal package. I have included it (as the documentation indicates to) into inst/rmd within the package directory.
In order to do this build or open any package you have access to
add the file to inst/rmd (create it if this doesn't exist)
rebuild the package
I then rebuild the package and open a new project. I load my new package and attempt to run the document via the render command using the system.file command to locate the .rmd like so
rmarkdown::render(input = system.file("rmd/writeFile.Rmd", package="MyPackage"),
output_file = "writeFile.pdf", output_dir = "./Cars/)
This will render the report from the package build into the folder from output_dir, however, there are a number of pitfalls here. First, if I omit the output_dir argument, the report will render into the package library, usually located in the libraries r installation in the c drive. This is however fixable.
What I can't get around is that when the .Rmd hits the write.csv() then (I believe) the .Rmd is being rendered in the package environment at the time, the working directory of which is the package library folder, not the current project directory.
The Questions
How can I inform the template in the package what the current working directory is for the rstudio project? I'm vaguely aware there might be a rstudio api package? I have nearly no understanding of what it is though, or if this would provide a solution.
If this is either outright impossible or just potentially a very bad idea how can I modify the workflow to successfully retrieve a number of r object outputs into the environment or the working directory, on the call to the report, without having to modify the report for each different project? Further, why specifically is this approach such a bad plan?
In order to close this off:
I have selected to keep the .Rmd included in the package. The .Rmd need to move and be versioned with the package as that holds the functions they use to run.
In order to meet my requirements I style the documents to grab the working directory via the rstudio api in the form.
write.csv(mtcars, file = paste0(rstudioapi::getActiveProject(), "mtcars.csv"))
Having tested #CL's answer, this also runs and is not dependant on Rstudio as an IDE, however I know that these documents will
Always be accessed via the rstudio IDE
Always be accessed from within a specific project
I fear (though have not tested) that there would be the potential for other impacts from setting the working directory for the file to be artificially booted into a different WD. Potentially this could be things like child documents I might want to include later, or other code that might need to be relevant to the file path of the package installation, not the project. In this way I think (If I interpreted Yuhui correctly) the r doc is still the centre of it's own universe. It just writes it's data into another one :)