0

I have been trying to create a private r package which would be managed using our company gitlab. I was following the tutorial from the R Packages book on creating a package from scratch, however I get stuck at 2.5 use_git().

  • Use git successfully initialises the git repo, however
  • There are no comments in the commit history
  • I cannot set (or see) the checkbox to enable version control
  • I cannot set the origin of the git repo to our gitlab

Screenshot of: Tools -> Project Options

I have successfully created projects in the gitlab and cloned them, and opened them in RStudio. Using a project initialised from gitlab I can push/pull etc. but this is my first attempt at creating a package.

I guess it must be simple but I am not seeing what I am doing wrong. All help will be greatly appreciated.

I am running

  • Win 10 64bit
  • RStudio 1.3.1093

Running version() returns the following:

> version

platform       x86_64-w64-mingw32          
arch           x86_64                      
os             mingw32                     
system         x86_64, mingw32             
status                                     
major          4                           
minor          0.3                         
year           2020                        
month          10                          
day            10                          
svn rev        79318                       
language       R                           
version.string R version 4.0.3 (2020-10-10)
nickname       Bunny-Wunnies Freak Out 

SOLUTION: Thanks to NelsonGon for putting me onto the right path.

  1. Run usethis::use_git_remote(name = "firstr", url = "https://mycompanygit/username/firstr.git") from the console
  2. Run git push -u firstr master from the terminal (to push the git project from the local repo to the gitlab and set the gitlab as the upstream ref), this was a helpful site
  3. Close and restart R or the "Push/Pull" buttons will be greyed out

I do have a follow on question, how can step two be done from the R console, is there are command in the usethis:: package that does that?

lifedroid
  • 164
  • 2
  • 7
  • Does does `git remote -v` return what you expect and what is the issue with package creation? From your screenshot, you have no origin set. Perhaps set it with `git remote set-url origin` or add origin? – NelsonGon Jan 14 '21 at 10:53
  • @NelsonGon thanks for the info. After running `git_remotes()` I could see that the origin was on my local pc. I used `use_git_remote(name = "firstr", url = "https://mycompanyserver/username/firstr.git", TRUE)` and it set the expected origin for fetch and push. I attempted to push everything as an initial upload however when I went to our gitlab the project hadn't been pushed. Additionally the url specified still didn't show up in the project options as the origin, even though it is displayed when I run `git_remotes()`. I am guessing there is a simple step I am missing – lifedroid Jan 15 '21 at 10:27
  • 1
    @NelsonGon I was successfully able to push my project to our company git. I did it using the terminal window with the command: `git push firstr master` I then checked the gitlab and it was there, so I made a comment in a file via the web IDE however I am unable to pull to RStudio and see that change. Running `git remote -v` does show it as both (fetch) and (push). – lifedroid Jan 15 '21 at 11:13
  • I honestly do not rely on RStudio's git interface so mostly do things at the Terminal. Could you generate ssh keys and add those to both RStudio and Gitlab? Kinda weird that you can't pull. – NelsonGon Jan 15 '21 at 11:32
  • 1
    I found I couldn't pull because I didn't specify the push as being an upstream reference. After rerunning the push command with the `-u` option (and restarting R) it worked fine. Thanks for the pointers. – lifedroid Jan 15 '21 at 11:52

1 Answers1

0

POST OF SOLUTION SO IT CAN BE MARKED AS SOLVED Run the following:

  1. usethis::use_git_remote(name = "firstr", url = "https://mycompanygit/username/firstr.git") from the console
  2. Run git add .
  3. Run git commit -m "Initial commit"
  4. Run git push -u firstr master from the terminal (to push the git project from the local repo to the gitlab and set the gitlab as the upstream ref)
  5. Close and restart R or the "Push/Pull" buttons will be greyed out

Edit 26/02/21: I missed steps 2 & 3 in my initial answer post

lifedroid
  • 164
  • 2
  • 7
  • A useful [link](https://stackoverflow.com/questions/3311774/how-to-convert-existing-non-empty-directory-into-a-git-working-directory-and-pus) – lifedroid Jan 18 '21 at 04:29