Lecturer: Michael Lydeamore
Department of Econometrics and Business Statistics
Aim
git
project from an existing local folderSuppose you have a folder on your computer which is not version controlled, and you decide that you would like to start tracking it.
You go to GitHub and create a repo over there. You now have two options:
git init
to create a git
repostiroygit remote add origin git@github.com:...
git push -u origin main
Option 2 is preferred because it reduces duplication.
GitHub even gives you instructions:
The -u
flag says to link remote origin
to branch main
. it is a one time operation.
Remember you can verify your remotes using git remote -v
Public repos in GitHub make your work publicly available and therefore it is important to establish how your work should be acknowledged if someone else wants to use it.
Public repositories on GitHub are often used to share open source software. For your repository to be truly open source, you’ll need to license it sot that others are free to use, change and distribute the software.
You can add a license from:
Licenses go in the root of the directory. Some information about licenses is sometimes included in README.md
as well, but this is not required.
It used to work I’m sure!
ggplot
look funny nowGenerally, this is because a version of a package has updated.
The primary solution for dependency management (which is far from perfect) is renv
The idea is to create a project-specific library to ensure a project has a record of which version of R packages are used.
renv
work?When we load a library, what exactly is going on?
R searches in a collection of places for the dplyr
package, and loads it.
These places are called library paths.
You can change the library path, and you can view them using .libPaths()
Your default library path is probably something like:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library
If you want to find a package, you can use find.package("dplyr")
renv
sets up a project-specific library path to keep your packages from interacting with eaach other.
renv
workflowVia the R console:
renv::init()
to initialise the projectrenv::snapshot()
to save the state of the local library to a lockfilerenv::restore()
to reverty our packages to the state encoded in the lockfileThe lockfile contains all the information about which package version is being used, and makes your environment reproducible.
In collaborative projects, you may want to ensure everyone is working with the same environment
It helps protect against changes between different versions of packages.
By sharing the lockfile, your collaborators will be using the same version of packages that you are using, without breaking their own installs.
Observe the changes in libPaths
, the new files, and the lockfile.
“If you’re using a version control system with your project, then as you call renv::snapshot()
and later commit new lockfiles to your repository, you may find it necessary later to recover older versions of your lockfiles. renv provides the functions renv::history()
to list previous revisions of your lockfile, and renv::revert()
to recover these older lockfiles.”
Currently, only Git repositories are supported by renv::history()
and renv::revert()
.
Each project contains only a single renv.lock
There are some helper functions:
renv::history()
: find prior commtis in which the lockfile has changedrenv::revert(commit = SHA1)
: Revert the lockfile to a state at a previous commitImportant
Make sure to commit the lockfile often, and call renv::snapshot()
when you’re updating packages! This is the only way the changes can be recorded and shared.
renv::init()
renv::snapshot()
renv.lock
with others via version control.Once collaborators clone the repository, they also run renv::init()
.
This will automatically install the packages declared in the lockfile.
By doing this, they can work in your project using exactly the same R packages that you used when the lockfile was generated.
Important
ETC5513 Week 10