Creating a template for projects in RStudio - r

I want to create a template that creates a project in RStudio with a few non-empty .R files and a directory.
So for example, I create a project named 'project1', I want it to create a regular project, with 3 .r files and a sub-directory.
So my project is located at ~/Desktop/MyProject/
and in this folder I'll have 3 files named file1.r, file2.r, file3.r and a directory called 'data'.
And also, in file1.r there will be the line library(ggplot2).
I've tried reading the project template documentation written here but I got lost a bit.

Related

RStudio: Running .Rprofile in source file location

I have set up a workflow governed by a Makefile.
Under code/ I have multiple *.r scripts each typically responsible for creating one output file (typically an RData file but could also be csv exports or png images, any file in principle)
code/.Rprofile contains some helper functions to bootstrap the whole project directory system and sources some helper functions etc.
The scripts in code/ need this functionality to work properly.
RStudio has the convenient menu entry to set working directory to source file location.
But could I also make it run .Rprofile in that directory if found? Or really just start R a fresh from the directory of the source file?

Roxygen not generating .Rd files with directory tree

I have main directory with R project file, project is called "knn". I have subdirectories source (contains all .R files), data (contains .csv files used in project) and man (.Rd files should go there). I also have correct DESCRIPTION and NAMESPACE (generated by Roxygen) files in main directory.
When I use roxygen2::roxygenize() in my main project directory, I get Loading knn and no files. When I use devtools::document() in my main directory, I get Updating knn documentation Loading knn. I have no documentation or .Rd files whatsoever.
I've even tried moving all my .R files to main directory - same results. How can I generate my documentation? What am I doing wrong?
As commented, Roxygen assumes all your .R scripts are in a directory called R.

Add existing scripts to an Rstudio project

I'm working in Rstudio and have multiple scripts open that have different working directories; however, each working directory exists within a larger folder on my computer (see below). Is it possible to add these scripts to an Rstudio Project without reorganizing all my files and changing each script's working directory?
File structure on computer:
Folder A
~~Folder 1
~~Folder 2
~~Folder 3
Say I have 3 scripts open, each with a working directory of either Folder 1, 2, or 3. Can I create a project that incorporates all three scripts. Say, set working directory to "Folder A"
Thanks much.
Technically, you can change working directory programmatically within a project, but this is considered a very poor practice and is strongly recommended against. However, you can set working directory at a project's top level (full path to Folder A, in your example) and then refer to scripts and objects, located in Folders 1-3 via corresponding relative paths. For example: "./Folder1/MyScript.R" or "./Folder2/MyData.csv".
It should be possible to create a project in the larger folder. You could even construct a simple master script in Folder A to manage this workflow:
setwd("./Folder 1")
source("scriptx")
setwd("..")
setwd("./Folder 2")
source("scripty")
setwd("..")
setwd("./Folder 3")
source("scriptz")
setwd("..")
Compared to source("Folder 1/scriptx") which runs each script within Folder A the master script would be running each script within it's own folder. Just make sure to use setwd("..") after running code in each folder and you can even run code in between to save output to the main Folder A.
If your workflow always creates folders in this manner I don't see how this would not be reproducible if you used relative paths. Albeit platform dependent, this modified version would create folders on the fly and run scripts kept in Folder A.
system("mkdir Folder_1")
setwd("./Folder_1")
source("../Folder A/scriptx")
setwd("..")
Notice here that when running terminal commands in R, it is recommended avoid spaces in directory or file names.

How to add external Java libraries' folder to Jython project in PyDev?

I am completely new to Python/Jython/PyDev.
I just tried to add a folder containing JARs as an External Source Folder to my Jython project as shown here: https://stackoverflow.com/a/12583946/2018047
Unfortunately, imports only resolved when adding the JARs individually (instead of their containing folder).
Do I have to add something like __init__.py files to those directories to make it work on a per folder basis? How are the init files structured?

How to create a empty folder with QuaZIP

I've successfully created folders and files inside a ZIP file with QuaZIP, but to create a folder i used a not elegant way, that creates a file without name inside the ZIP file. Is there any way to create empty folders inside a ZIP file without create a file inside that folder?
Code to create folder:
QuaZip zip("path_to\\zipFile.zip");
zip.open(QuaZip::mdCreate);
QuaZipFile outFile(&zip);
outFile.open(QIODevice::WriteOnly, QuaZipNewInfo("SomeFolder\\"));
outFile.close();

Resources