Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify factory interaction with Github #86

Open
nsbatra opened this issue Jul 8, 2021 · 8 comments
Open

simplify factory interaction with Github #86

nsbatra opened this issue Jul 8, 2021 · 8 comments

Comments

@nsbatra
Copy link

nsbatra commented Jul 8, 2021

Hi Tim,

I am trying to create a Github repo that consists only of the contents of a report factory, but am struggling. To me this seems to be a natural use-case for reportfactory. It seems that there should be a more simple way to achieve this (perhaps an option to "convert" an existing R project into a factory, instead of creating a new factory folder within it?).

Below is an example of the desired structure of the repo (note that there is one R project file, and the report_sources and outputs folders are also in the root with the R project file).

Rproject file
report_sources folder
outputs folder
data folder
scripts folder
.gitignore
.here
factory_config
README
etc.

I assumed (and I think many would) that I could begin an R project locally, create a factory, and sync with Github fairly easily to achieve a repo structure like the above. There were a few barriers:

As we know, the default behavior of reportfactory is to create a folder within the working directory that contains the factory (including R project file, sources and outputs folders, etc.). Thus, if you follow these instructions to link an R project and Github repo (New project, Github first) you create a repo and clone it locally by creating a new R Project with version control and entering the .git address. However this means that when you subsequently create a reportfactory in this R project, there will be two R projects! One for the original repo, and one within a folder that is the reportfactory. Not ideal. Aiming for the simple structure above with only one R project file.

So, I tried an alternative method of linking a project to Github (Existing Project, Github last). This involves making an R project that is not linked to Git or Github, then creating a report factory, and then linking it to Github with usethis::use_git() and usethis::use_github()` (as explained in the weblink above). This does not solve the underlying problem because there are still two R projects.

I also tried to modify the path = argument in the new_factory() command, thinking that I could just provide a directory one level higher (path = "C://...") and get only the factory where I wanted it (then link this existing report factory R project to a new Github repo using usethis as above). This was a disaster as somehow the name of this new factory became "report_sources"! When I manually changed the name to be more appropriate, no reports would compile because it "Expected the name of the factory to be "report_sources" ").

This is the approach that (almost) worked:

  • Open RStudio, close any existing project, set the working directory to be folder above where I want the new factory (I used setwd(utils::choose.dir()) to interactively set the working directory). Then I ran report_factory::new_factory(). Voila, I had a local reportfactory where I wanted it, with only one R project. Now, following the instructions above, I created an empty Github repository, ran usethis::use_git() to get a Git pane in RStudio in that local project, then assigned the remote origin:

image

Finally I had to do a bit of dancing (make a branch, push apparently no commits up, and then PR the branch into main), but I achieved a remote "test" branch that looked like this (exactly what I wanted!):

image

But when I tried to PR into main... it fell apart again:
image

I tried to compile a report locally to see if at least that would work? Sadly not.
image

So, I guess this is a call for help. I hope there's something I missed. How would you go about this?
Much thanks!
Neale

@TimTaylor
Copy link
Contributor

Hi Neale

There's an argument to to new_factory that allows you not not use a .Rproj file, i.e.

new_factory(use_rproj = FALSE)

Does that do what you want? Also note that there is a similar use_here argument that you may also want in this configuration.

@nsbatra
Copy link
Author

nsbatra commented Jul 9, 2021

Hi Tim,
An update as I continue to troubleshoot.

I hope I've missed something simple, but setting these arguments to FALSE does not seem to create a viable factory. I keep getting this callr error when I create a clean empty R project, create a factory within it with those settings, and then try to compile the example report (Git not involved).

image

image

I also tried use_rproj = F and use_here = F and then to cut/paste the factory files up one level into the root R project folder, trying with & without editing the factory_config file to reflect the correct R project name. No luck either.

As I look into the code of the reportfactory functions, I can see that callr::r is used in compile_reports()
If you have time, I would appreciate your advice on how one can best integrate a Github repo and reportfactory.

If you think this warrants a quick call I am available. Or, let me know if you suggest I just accept that the factory will be a subfolder within the root.

thanks,

@TimTaylor
Copy link
Contributor

I'll dig in to this now. Can you post the result of sessionInfo() for me below?

@TimTaylor
Copy link
Contributor

Hi Neale, please install the latest version from GitHub. I've change the example report as for multiple reasons this was causing an issue. This should all work now but I'll keep this issue open for you to confirm. Happy to jump on a call if not resolved.

Cheers

@nsbatra
Copy link
Author

nsbatra commented Jul 9, 2021

Thanks for these tips/corrections Tim. For posterity, here is the procedure that worked for me (I will eventually add this to the Handbook):

  • Install development version of reportfactory
  • Create empty Github repo "oxygen_study"
  • Clone repo to local computer as root folder and R project named "oxygen_study". Open.
  • Create new factory with reportfactory::new_factory(use_here = F, use_rproj = F, factory = "oxygen_study" (assigning this factory name to that of your top-level R project is important, as it writes this in the factory_config file).
  • Open file explorer, and transfer (cut & paste) contents of factory sub-folder to the project root folder (if you copy & paste, any compile_reports() commands will still run only within the old factory sub-folder). Make any gitignore and README from the factory take precedence when you paste.
  • Delete old factory sub-folder to clean your repo
  • Commit and push

Thanks for your help!

@nsbatra
Copy link
Author

nsbatra commented Jul 9, 2021

I could see a "convert" functionality that does this cut/paste for you as a useful feature request.
If I had the time I'd try to submit a PR myself but that is unlikely anytime soon.

@TimTaylor
Copy link
Contributor

Let me reread your comments and digest this a bit more as that seems far too convoluted. Will DM you about a call next week as this should be as simple as creating a new factory and running something like use_git within it (although maybe I'm misunderstanding your use case).

@nsbatra
Copy link
Author

nsbatra commented Jul 9, 2021

Great, thanks Tim. Yes I think something with use_git() and use_github() could help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants