{"id":112,"date":"2021-08-24T16:20:18","date_gmt":"2021-08-24T16:20:18","guid":{"rendered":"https:\/\/haddingtonsolutions.com\/?p=1"},"modified":"2022-10-10T18:16:33","modified_gmt":"2022-10-10T18:16:33","slug":"r-on-windows-365","status":"publish","type":"post","link":"https:\/\/haddingtonsolutions.com\/index.php\/2021\/08\/24\/r-on-windows-365\/","title":{"rendered":"R Studio on Windows 365"},"content":{"rendered":"<p><span style=\"color: #000000;\">Let&#8217;s start off by <a style=\"color: #000000;\" href=\"https:\/\/cran.r-project.org\/bin\/windows\/base\/\" target=\"_blank\" rel=\"noopener\">downloading R<\/a> for our new Windows Machine.<\/span><\/p>\n<p><span style=\"color: #000000;\">Next we will download the most popular IDE for R, called <a style=\"color: #000000;\" href=\"https:\/\/www.rstudio.com\/products\/rstudio\/download\/#download\" target=\"_blank\" rel=\"noopener\">R studio<\/a>.<\/span><\/p>\n<p><span style=\"color: #000000;\">Once they are both installed open up R Studio and you should see a screen looking similar to below.<\/span><\/p>\n<p><span style=\"color: #000000;\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone wp-image-154 size-large\" src=\"https:\/\/haddingtonsolutions.com\/\/srv\/htdocs\/wp-content\/uploads\/2021\/08\/Rmain-screen-1024x619.png\" alt=\"\" width=\"1024\" height=\"619\" \/><\/span><\/p>\n<p><span style=\"color: #000000;\">Next thing we need to do is to grab an API key to get the data we want.<\/span><\/p>\n<p><span style=\"color: #000000;\">I signed up for <a href=\"https:\/\/pro.coinmarketcap.com\/\" rel=\"nofollow\">https:\/\/pro.coinmarketcap.com\/<\/a> account.<\/span><\/p>\n<p><span style=\"color: #000000;\">This was chosen for a number of reasons<\/span><\/p>\n<ul>\n<li><span style=\"color: #000000;\">There is an R package specifically built for this usage called Coinmarketcapr &#8211; &#8220;Big Win&#8221;<\/span><\/li>\n<li><span style=\"color: #000000;\">They provide an API key on the free tier with pretty high usage limits (300 calls a day)<\/span><\/li>\n<li><span style=\"color: #000000;\">Lastly, its cryptocurrency data so whats not to love!<\/span><\/li>\n<\/ul>\n<p><span style=\"color: #000000;\">so grab your API key and get back to R studio.<\/span><\/p>\n<p><span style=\"color: #000000;\"><img decoding=\"async\" class=\"alignnone wp-image-156 size-large\" src=\"https:\/\/haddingtonsolutions.com\/\/srv\/htdocs\/wp-content\/uploads\/2021\/08\/api-key-1024x393.png\" alt=\"\" width=\"1024\" height=\"393\" \/><\/span><\/p>\n<p><span style=\"color: #000000;\">In R Studio,\u00a0type<\/span><\/p>\n<p><span style=\"color: #000000;\">install.packages(&#8220;coinmarketcapr&#8221;)<\/span><\/p>\n<p><span style=\"color: #000000;\">in the bottom left &#8220;Console&#8221; tab of R studio.<\/span><\/p>\n<p><span style=\"color: #000000;\">Wait for the packages to install.<\/span><\/p>\n<p><span style=\"color: #000000;\">Then in the top left view copy and paste the text below, but do not forget you will need to replace the API text I have with the one you get from your pro coinmarket cap account.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\">library(coinmarketcapr)<\/span><\/p>\n<p><span style=\"color: #000000;\">myapikey &lt;- &#8216;ThisismyAPIkeygetyourown&#8217;<\/span><\/p>\n<p><span style=\"color: #000000;\">coinmarketcapr::setup(myapikey)<\/span><\/p>\n<p><span style=\"color: #000000;\">cryptos &lt;- get_crypto_listings<\/span><\/p>\n<p><span style=\"color: #000000;\">cryptos2 &lt;- cryptos[,-7]<\/span><\/p>\n<p><span style=\"color: #000000;\">cryptos3 = data.frame(lapply(cryptos2, as.character), stringsAsFactors=FALSE)<\/span><\/p>\n<p><span style=\"color: #000000;\">write.csv(cryptos3,&#8221;C:\\\\R_script\\\\R_output\\\\R_Out.csv&#8221;, row.names = FALSE)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><img decoding=\"async\" class=\"alignnone wp-image-159 size-full\" src=\"https:\/\/haddingtonsolutions.com\/\/srv\/htdocs\/wp-content\/uploads\/2021\/08\/r-console-view.png\" alt=\"\" width=\"709\" height=\"234\" \/><\/span><\/p>\n<p><span style=\"color: #000000;\">There are a few things happening above worth knowing.<\/span><\/p>\n<p><span style=\"color: #000000;\">We are firstly telling R to use a package called coinmarketcapr and we are feeding it our API key.<\/span><\/p>\n<p><span style=\"color: #000000;\">We are then creating a variable called cryptos which is a data frame of the get_crytpo_listings command. This is a 29 column dataframe of the top 100 crypto currencies.<\/span><\/p>\n<p><span style=\"color: #000000;\">cryptos2 &lt;- is the variable we are using to store the dataframe above but we are removing the 7th column. This is the &#8220;Tags&#8221; column and it contains multiple commas. As these are the standard delimiter in ETL jobs it is best to remove them now.<\/span><\/p>\n<p><span style=\"color: #000000;\">cryptos3 = This will convert all variables to class &#8220;character&#8221;, which will be required to generate a .csv<\/span><\/p>\n<p><span style=\"color: #000000;\">write.csv is exactly what it means. Be aware that when adding the path to use \\\\ rather than \/\/.\u00a0 You should save your R script in the same path as I have above in order to better replicate the exact process you see on screen.<\/span><\/p>\n<p><span style=\"color: #000000;\">So we now have a working R script that pulls data from an API and modifies it slightly. It then creates it as .csv which is the prefered file type for most ETL tools.<\/span><\/p>\n<p><span style=\"color: #000000;\">Simples!<\/span><\/p>\n<p><span style=\"color: #000000;\">In the next post I will show you<\/span><\/p>\n<ul>\n<li><span style=\"color: #000000;\">How to install and set up Talend (Which is an pain, but worth it!)<\/span><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s start off by downloading R for our new Windows Machine. Next we will download the most popular IDE for R, called R studio. Once they are both installed open up R Studio and you should see a screen looking similar to below. Next thing we need to do is to grab an API key [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":187,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_wpcom_ai_launchpad_first_post":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-112","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"jetpack_featured_media_url":"https:\/\/haddingtonsolutions.com\/wp-content\/uploads\/2021\/08\/r-studio.png","_links":{"self":[{"href":"https:\/\/haddingtonsolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haddingtonsolutions.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haddingtonsolutions.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haddingtonsolutions.com\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/haddingtonsolutions.com\/index.php\/wp-json\/wp\/v2\/comments?post=112"}],"version-history":[{"count":1,"href":"https:\/\/haddingtonsolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/112\/revisions"}],"predecessor-version":[{"id":188,"href":"https:\/\/haddingtonsolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/112\/revisions\/188"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/haddingtonsolutions.com\/index.php\/wp-json\/wp\/v2\/media\/187"}],"wp:attachment":[{"href":"https:\/\/haddingtonsolutions.com\/index.php\/wp-json\/wp\/v2\/media?parent=112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haddingtonsolutions.com\/index.php\/wp-json\/wp\/v2\/categories?post=112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haddingtonsolutions.com\/index.php\/wp-json\/wp\/v2\/tags?post=112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}