Use the same styles.css file for multiple Rmarkdown projects - css

I have a styles.css file (which also refer to a logo png file) I use for my Rmarkdown documents that I'd like to be available to all my projects. My current workflow is to copy it to each of my repo, but that also means I have to update all my repos when I want to make a change.
Any ideas? Might be as simple as hosting it in a S3, but I'm not sure that rmarkdown allows that.

Related

Using subdirectories with quarto and RStudio

Please consider the following.
I like to structure my R projects with different subdirectories. Using bookdown or quarto seems to make this quite difficult since both like to have their source files (.Rmd or .qmd) in the project directory. I was hoping that this will get easier with quarto but this does not seem the case, although it should be possible according to this post.
Problem description (replicable example)
Start a new quarto book project in RStudio: File > New Project > New Directory > Quarto Book.
This will create several .qmd files in the R project directory. Now create new subdirectories. Starting from the R project directory: scripts/qmd.
If we put all .qmd files from the R project directory into scripts/qmd, we also need adapt their path in the _quarto.yml (e.g., from index.qmd to / scripts/qmd/index.qmd).
After doing so and pressing the Render button, we receive the ERROR: Book contents must include a home page (e.g. index.md).
Putting only the index.qmd file back into the R Project directory (and adapt the _quarto.yml), the book can be rendered.
Question
How can we put all .qmd files into a dedicated subdirectory?
Edit (ignore below)
Originally the below question was also asked but is now answered: quarto does not seem to have a "merge-knit" option like bookdown (see here). This unfortunately makes quarto useless for my use case.
If this is not possible, how can we make sure that object created in the R project directory are accessible for the .qmd files in the subdirectories? (setting execute-dir: project as suggested here did not work for me.
I'm assuming your purpose is just a specific personal preference for file organization.
You can have a large portion of your content in subdirectories (and that's my understanding of what Alison's blog post refers to), but you still need to have your index.qmd in the root. For example, you can have a subdirectory for projects, another one for posts, another one for tutorials, like Alison does.
In any case, one way of achieving what you want is by using pre- and post-render scripts.
You could move all the files from the scripts/qmd directory before rendering and then move them all back afterwards.
pre-render: mv scripts/qmd/*.qmd .
post-render: mv *.qmd scripts/qmd
Incidentally, that doesn't match my own personal preference ;-)
#Lucas A. Meyer, I tested the pre-render and post render options you suggested above, however, it throws an error after moving the file from my subdirectory to the project root:
ERROR: NotFound: The system cannot find the file specified. (os error 2)
Then, it fails to render the file and move it back to the original subdirectory location.
I then set execute-dir: project in my .yml file thinking it was trying to execute in the wrong folder, but it did not change anything.
P.S. I would have added as a comment, but my reputation is not high enough, yet. :(
UPDATE1:
I thinking I found a workaround for the time being. I've include the following project options beneath the project: header:
output-dir: subdir1/subdir2 Moves the html file, only.
post-render: xcopy *_files subdir1/subdir2 /E Copies the supporting files over.
The mv shell command can't be used for directories or you get the Directory Not Empty error.`

Unable to render new .Rmd files to html after the recent blogdown update

I have a large site built on blogdown. Every day, there are several new .Rmd files that need to be rendered to html files. Before this recent blogdown update, I relied on serve_site() to render the new .Rmd files. After the update, as mentioned in the "release notes", we wouldn't need to call serve_site() explicitly; however, if I didn't call serve_site(), I cannot seem to get the html files rendered, and cannot preview the site in Rstudio. The public/ did not get updated either. (Even if I call serve_site(), I still cannot get the html files rendered...)
I noticed that blogdown::build_site(build_rmd = TRUE) can render all rmd files, but I don't want to rebuild the whole site. I wondered if I miss anything, or is there a way that I can only get the new .Rmd files render to html and copied to the public/ directory automatically in this new version? Thank you so much!
With the latest version of blogdown on CRAN, serve_site() is called automatically when you open the RStudio project. If you add new Rmd files after that, they should be compiled automatically, but if you add them before you open the RStudio project, or call serve_site(), they won't be recognized. You can install the development version of blogdown (in which I just pushed a change), and these new Rmd files should be automatically compiled when you serve_site():
remotes::install_github('rstudio/blogdown')
The quickest fix is to revert to the previous version of blogdown until the bug is documented and/or fixed.
I would recommend reverting using the versions package, it makes the process quite painless.
https://cran.r-project.org/web/packages/versions/versions.pdf
Best of luck!

Styles from a github css file

Can I use a styles.css file uploaded on GitHub as styles for multiple projects? I'm trying to define a default style for my projects here: https://raw.githubusercontent.com/GhitaB/default-design/master/styles.css
I prefer to link this file instead of copying it in multiple projects.
RawGit serves raw files directly from GitHub with proper Content-Type headers.
Or, consider using Github Pages
Here we need to distinguish between duplication of code and resources. What you don't want is copying code, because those files would diverge and you'd need to repeat every change for all of them. Having one file uploaded to multiple servers, however, shouldn't be a problem as long as you have one place to edit them all at once.
For this case there's Git submodules. The idea is basically having a repository with the shared part and then including that repository in a specified path in your other projects. You can read more about it here: https://git-scm.com/book/en/v2/Git-Tools-Submodules
This way all your IDE-based and external tools will still work and your website can be deployed as a whole. If, at some point in the future, you decide to have separate CSS files, you can simply replace the submodule with a file and you won't need to change the paths in HTML.
Of course, you can also use the same exact resource in multiple projects simply by pointing them to the same URI, but then the uncoupling might be harder afterwards and you can't see the file in your IDE.

Can I generate .Rd files without roxygen2 annotations

Is it possible to generate .Rd files for R functions without manually writing roxygen annotations?
I know one method is to use prompt() but this does not look at arguments or return values.
Can it done through any other command or with RStudio?
Yes, you can just write the files by hand, like most of us did for a long time. See Writing R Extensions for details on the format.
You can source the scripts you want to create a package out of and then use the command
package.skeleton(name = 'MyPackage')
This will create a package based on everything in your current environment so make sure your environment only contains what is necessary to create your package. If you are using devtools (which I recommend you do) then do this outside another folder. This will create a "man" folder that contains .Rd files that serve as the basic template for everything that you sourced that requires documentation. This would save some time as opposed to writing them all by hand.
If you are using devtools, then copy these files into the other 'man' directory in your project.

How to use the modified bootstrap in Flat-UI in a Meteor app?

I am using bootstrap in Meteor and found that there is a modified flat design here: http://designmodo.com/demo/flat-ui/. Among the files seems to be a modified set of Bootstrap files. Is it possible to somehow use those css and js files to override the default bootstrap files to get the Flat-UI in a meter app? Thank you!
it's quite simple:
unzip the contents of the flat-ui-master.zip from the flatui site, then follow these steps:
create these folders in your app root: /client/stylesheets
copy the contents of the .zip into /stylesheets
remove the index.html and README.md files as they might cause your app to crash, and are not needed
meteor automatically takes care of the rest.
Although manually insert files works, I'm using meteor package jss:flat-ui
meteor add jss:flat-ui
it will automatically add flat-ui and twbs:bootstrap.
Note that, it might be better to remove any bootstrap package before installing this, I've been in a project that has mizzao:bootstrap installed and the login ui not working, so I remove mizzao:bootstrap and reinstalled flat-ui to make it work.
You can use whatever css you want to, Meteor don't care.
I wouldn't add the bootstrap meteor package though, I'd just download the css files you want and place them in your project. That way you know exactly what files are used and can easily make changes.
Here's some info on how to structure your app: https://github.com/oortcloud/unofficial-meteor-faq#where-should-i-put-my-files
I created a shell script to generate a custom bootstrap Meteor package from either a precompiled distribution, or from your own clone of the Bootstrap Git repository.
You can find it here, along with usage information: https://github.com/wojas/meteor-package-bootstrap
Just unpack the ZIP file containing the files and run this command from inside the theme folder:
/path/to/meteor-package-bootstrap.sh $your_meteor_project/packages/bootstrap

Resources