{"id":314,"date":"2014-04-21T19:18:04","date_gmt":"2014-04-21T19:18:04","guid":{"rendered":"http:\/\/kourentzes.com\/forecasting\/?p=314"},"modified":"2014-12-18T10:44:03","modified_gmt":"2014-12-18T10:44:03","slug":"how-to-use-r-packages-from-github","status":"publish","type":"post","link":"https:\/\/kourentzes.com\/forecasting\/2014\/04\/21\/how-to-use-r-packages-from-github\/","title":{"rendered":"How to use R packages from GitHub"},"content":{"rendered":"<p style=\"text-align: justify;\"><strong>Update: <\/strong>The following R commands will install a package directly from GitHub to R:<\/p>\n<pre>&gt; if (!require(\"devtools\"))\r\n    install.packages(\"devtools\")\r\n&gt; devtools::install_github(\"YYY\/ZZZ\")\r\n<\/pre>\n<p style=\"text-align: justify;\">where YYY is the GitHub username and ZZZ is the package name. For example to install TStools use:<\/p>\n<pre>&gt; devtools::install_github(\"trnnick\/TStools\")<\/pre>\n<p style=\"text-align: justify;\">This makes the process described below unnecessary, however if you want the &#8216;full&#8217; story read on!<\/p>\n<hr \/>\n<p style=\"text-align: justify;\">I typically use <a href=\"https:\/\/www.rstudio.com\/\">RStudio<\/a> in Windows when I code in R, so I will give my examples using that. However this is not crucial for the process, as long as you have some basic knowledge of building packages.<\/p>\n<p><strong>Step 1. Download the files from GitHub<\/strong><\/p>\n<p style=\"text-align: justify;\">I will first save the files locally. I will be using <a href=\"https:\/\/github.com\/trnnick\/TStools\">TStools<\/a> for this example. At the GitHub page you will see at the bottom-right corner a <strong>Download ZIP<\/strong> button. Use that to get a full copy of the directory.<\/p>\n<p><a href=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig1_.png\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-315 size-medium aligncenter\" src=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig1_-300x190.png\" alt=\"githubR.fig1\" width=\"300\" height=\"190\" srcset=\"https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig1_-300x190.png 300w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig1_-150x95.png 150w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig1_.png 600w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">Unzip the contents of the file in a temporary directory.<\/p>\n<p><strong>Step 2. Get Rtools if you don&#8217;t have it already<\/strong><\/p>\n<p style=\"text-align: justify;\">Rtools is a collection of resources for building R under Microsoft Windows. If you have built a package in the past chances are that Rtools is already installed. If you don&#8217;t have it then you can get it <a href=\"http:\/\/cran.r-project.org\/bin\/windows\/Rtools\/\">here<\/a>. Install it and proceed to the next step.<\/p>\n<p><strong>Step 3. Create a new project in R<\/strong><\/p>\n<p style=\"text-align: justify;\">In RStudio go to <strong>File -&gt; New Project<\/strong><\/p>\n<p><a href=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig2_.png\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-316 size-medium aligncenter\" src=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig2_-300x190.png\" alt=\"githubR.fig2\" width=\"300\" height=\"190\" srcset=\"https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig2_-300x190.png 300w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig2_-150x95.png 150w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig2_.png 500w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">In the new window select <strong>Existing Directory<\/strong> and browse to the folder you unzip the file you downloaded from Github. Drill down until you see the R subdirectory and press\u00a0<strong>Select Folder<\/strong>.<\/p>\n<p><a href=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig3_.png\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-317 size-medium aligncenter\" src=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig3_-300x207.png\" alt=\"githubR.fig3\" width=\"300\" height=\"207\" srcset=\"https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig3_-300x207.png 300w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig3_-150x103.png 150w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig3_.png 600w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">and then click <strong>Create Project<\/strong>.<\/p>\n<p><strong>Step 4. Build the package<\/strong><\/p>\n<p style=\"text-align: justify;\">With the project loaded all that you need to do now is click on <strong>Build &amp; Reload<\/strong> in the <strong>Build<\/strong> tab. This is typically on the top-left of your screen. Rstudio will now build the package and it will add it to your package list.<\/p>\n<p><a href=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig4_.png\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-318 size-medium aligncenter\" src=\"http:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig4_-300x255.png\" alt=\"githubR.fig4\" width=\"300\" height=\"255\" srcset=\"https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig4_-300x255.png 300w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig4_-150x127.png 150w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig4_-660x561.png 660w, https:\/\/kourentzes.com\/forecasting\/wp-content\/uploads\/githubR.fig4_.png 771w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">If you can see the tabs <strong>Environment <\/strong>and <strong>History<\/strong>, but not <strong>Build<\/strong> then the project is not loaded or something went wrong in the project creation. Repeat step 3 or try looking for the project file in the folder you unzipped the files from GitHub. If there is an .Rproj file you should be able to load it by going to <strong>File -&gt; Open Project<\/strong> in the RStudio menu.<\/p>\n<p><strong>Step 5. Close project<\/strong><\/p>\n<p style=\"text-align: justify;\">The last thing you need to do is go to <strong>File -&gt; Close Project <\/strong>in RStudio menu. The package you downloaded from GitHub is now ready to use. You can now delete the temporary directory, including the project files.<\/p>\n<p style=\"text-align: justify;\">Of course there are many different ways to do this process. Here I highlighted one of the simplest ones (I think!).<\/p>\n<div class=\"SPOSTARBUST-Related-Posts\"><H3>Related Posts<\/H3><ul class=\"entry-meta\"><li class=\"SPOSTARBUST-Related-Post\"><a title=\"Tutorial for the nnfor R package\" href=\"https:\/\/kourentzes.com\/forecasting\/2019\/01\/16\/tutorial-for-the-nnfor-r-package\/\" rel=\"bookmark\">Tutorial for the nnfor R package<\/a><\/li>\n<li class=\"SPOSTARBUST-Related-Post\"><a title=\"R package: tsutils\" href=\"https:\/\/kourentzes.com\/forecasting\/2019\/01\/14\/r-package-tsutils\/\" rel=\"bookmark\">R package: tsutils<\/a><\/li>\n<li class=\"SPOSTARBUST-Related-Post\"><a title=\"Update for nnfor: reuse and retrain models\" href=\"https:\/\/kourentzes.com\/forecasting\/2017\/12\/11\/update-for-nnfor-reuse-and-retrain-models\/\" rel=\"bookmark\">Update for nnfor: reuse and retrain models<\/a><\/li>\n<\/ul><\/div><!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Update: The following R commands will install a package directly from GitHub to R: &gt; if (!require(&#8220;devtools&#8221;)) install.packages(&#8220;devtools&#8221;) &gt; devtools::install_github(&#8220;YYY\/ZZZ&#8221;) where YYY is the GitHub username and ZZZ is the package name. For example to install TStools use: &gt; devtools::install_github(&#8220;trnnick\/TStools&#8221;) This makes the process described below unnecessary, however if you want the &#8216;full&#8217; story read\u2026 <span class=\"read-more\"><a href=\"https:\/\/kourentzes.com\/forecasting\/2014\/04\/21\/how-to-use-r-packages-from-github\/\">Read More &raquo;<\/a><\/span><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[41],"tags":[45,49,39],"_links":{"self":[{"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/posts\/314"}],"collection":[{"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/comments?post=314"}],"version-history":[{"count":0,"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/posts\/314\/revisions"}],"wp:attachment":[{"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/media?parent=314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/categories?post=314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kourentzes.com\/forecasting\/wp-json\/wp\/v2\/tags?post=314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<!-- WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory. -->