{"id":52407,"date":"2020-07-14T12:28:44","date_gmt":"2020-07-14T16:28:44","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=52407"},"modified":"2023-02-16T16:04:37","modified_gmt":"2023-02-16T21:04:37","slug":"r-code-best-practices-r-trader","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-best-practices-r-trader\/","title":{"rendered":"R Code \u2013 Best Practices"},"content":{"rendered":"\n<p style=\"background-color:#afc3cc\" class=\"has-background\"><em>We take a look back at this classic piece from The R Trader on practical tips for Naming conventions, Files organisation, Syntax and Miscellaneous items.<\/em><\/p>\n\n\n\n<p>Nothing is more frustrating than a long piece of code with no standard way of naming elements, presenting code or organizing files. It\u2019s not only unreadable but more importantly not reusable. Unfortunately, unlike other programming languages, R has no widely accepted coding best practices. Instead there has been various attempts to put together a few sets of rules. This post is trying to fill the gap by summarizing and\/or extracting what I found\u202frelevant in those various attempts. It also includes some tips I came up with after years of using R on a daily basis.&nbsp;<\/p>\n\n\n\n<p><strong>1 \u2013 Naming conventions<\/strong>&nbsp;<\/p>\n\n\n\n<p>R has no naming conventions that are generally agreed upon. As a newcomer to R it\u2019s useful to decide which naming convention to adopt.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>There are 5 naming conventions to choose from:&nbsp;<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><em>alllowercase<\/em>: e.g.&nbsp;adjustcolor&nbsp;<\/li><li><em>period.separated<\/em>: e.g.&nbsp;plot.new&nbsp;<\/li><li><em>underscore_separated<\/em>: e.g.&nbsp;numeric_version&nbsp;<\/li><li><em>lowerCamelCase<\/em>: e.g.&nbsp;addTaskCallback&nbsp;<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><em>UpperCamelCase<\/em>: e.g.&nbsp;SignatureMethod&nbsp;<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Strive for names that are concise and meaningful&nbsp;<\/li><li>Generally, variable names should be nouns and function names should be verbs.&nbsp;<\/li><li>Strive for names that are concise and meaningful&nbsp;<\/li><li>Generally, variable names should be nouns and function names should be verbs.&nbsp;<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Not exported and helper functions always start with \u201c.\u201d&nbsp;<\/li><li>Local variables and functions are all in small letters and in \u201c.\u201d syntax (do.something,&nbsp;get.xyyy). It makes it easy to distinguish local&nbsp;vs&nbsp;global and therefore leads to a cleaner code.&nbsp;<\/li><li>File names should be meaningful and end in .R.&nbsp;<\/li><li>Pick one naming convention and stick to it. My suggestion:&nbsp;<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Files<\/strong>:&nbsp;underscore_separated, all lower case: e.g.&nbsp;numeric_version&nbsp;<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Functions<\/strong>:&nbsp;period.separated, all lower case: e.g.&nbsp;my.function&nbsp;<\/li><li><strong>Variables<\/strong>:&nbsp;lowerCamelCase: e.g.&nbsp;addTaskCall&nbsp;<\/li><\/ul>\n\n\n\n<p><strong>2 \u2013 Files&nbsp;<\/strong><strong>organisation<\/strong>&nbsp;<\/p>\n\n\n\n<p>They way files are&nbsp;organised&nbsp;helps making the code more readable. Similarly, the way the code is&nbsp;organised&nbsp;within a file has a significant impact on readability. Files might also have specific purposes. Some might contain only functions that will be used by other files, some might be used to update packages etc\u2026&nbsp;<\/p>\n\n\n\n<p><strong>2.1 \u2013 How to&nbsp;<\/strong><strong>organise<\/strong><strong>&nbsp;the files within a project?<\/strong>&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Use the project facility of RStudio each time you start working on a new project&nbsp;<\/li><li>Keep all of the source files for a project in one directory and use relative paths to access them&nbsp;<\/li><li>Separate files that contain functions that will be used by other parts of the code from the core of the code&nbsp;<\/li><li>Consider what working directory you are in when sourcing a script.&nbsp;<\/li><\/ul>\n\n\n\n<p><strong>2.2 \u2013\u202fHow to&nbsp;<\/strong><strong>organise<\/strong><strong>&nbsp;the code within each file?<\/strong>&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Start each file with a comment saying who wrote it and when, what it contains, and how it fits into the larger program.&nbsp;<\/li><li>Then load all required packages.&nbsp;<\/li><li>Then source required files if any&nbsp;<\/li><li>Then your code starts&nbsp;<\/li><li>Break code up into separate files (generally &lt;2000\u20133000 lines).&nbsp;<\/li><\/ul>\n\n\n\n<p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\">\n############################################################# <br><br>\n\n## Stuff I have to do <br><br>\n\n## thertrader@gmail.com &#8211; Feb 2018 <br><br>\n\n############################################################# <br><br>\n\n\u200b \n\n############################## <br><br>\n\n# 0 &#8211; Load librairies <br><br>\n\n############################## <br><br>\n\nlibrary(zoo) <br><br>\n\nlibrary(xts) <br><br>\n\n\u202f \n\n\u200b##############################  <br><br>\n\n# 1 &#8211; Source file  <br><br>\n\n############################## <br><br>\n\ndataPath <- \"C:\/some_directory\/some_sub_directory\/\" <br><br>\n\ndataFile <- \"some_functions.R\" <br><br>\n\nsource(paste0(dataPath,dataFile)) <br><br>\n\n\u202f \n\n############################## <br><br>\n\n# 2 &#8211; Start my code <br><br>\n\n############################## <br><br>\n\nmyPlot <- plot(data,type=\"l\") <br><br>\n<\/p>\n\n\n\n<p><strong>2.3 \u2013\u202fFiles of functions<\/strong>&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Write functions (and even a package) to automate things. Packages require a lot of discipline, documentation, and structure, which really help to enforce best practices&nbsp;<\/li><li>A file of functions must include related functions.&nbsp;<\/li><li>Put function definitions at the top of your file (if not too many). Function names can also be retrieved directly within RStudio.&nbsp;<\/li><li>Each function should have a single, focused task&nbsp;<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>If a function starts to get really complicated, consider separating parts out as separate functions. (Think reuse)&nbsp;<\/li><li>Precede each function with a comment regarding its task and the format of the input and output.&nbsp;<\/li><\/ul>\n\n\n\n<p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\">\n############################################################# <br><br>\n\n## Date Functions  <br><br>\n\n## <br><br>\n\n## dd.mm.yyyy.to.date: 22.10.2004 to a date <br><br>\n\n## yyyy-mm-dd.to.date: 2008-07-22 to a date <br><br>\n\n## dd-mm-yyyy.to.date: 12-05-2001 to a date <br><br>\n\n## <br><br>\n\n## thertrader@gmail.com &#8211; Jan 2008&#8230;  <br><br>\n\n############################################################ <br><br>\n\n\u202f \n\n## 22.10.2004 to a date <br><br>\n\ndd.mm.yyyy.to.date <- function(theDate) { <br><br>\n\n\u202fmyDate <- as.Date(theDate, format = \"%d.%m.%Y\") <br><br>\n\n\u202freturn(myDate) <br><br>\n\n} <br><br>\n\n\u202f \n\n## 2008-07-22 to a date <br><br>\n\nyyyy-mm-dd.to.date <- function(theDate) { <br><br>\n\n\u202fmyDate <- as.Date(theDate, format = \"%Y-%m-%d\") <br>\n\n\u202freturn(myDate) <br><br>\n\n} <br><br>\n\n\u202f \n\n## 12-05-2001 to a date <br><br>\n\ndd-mm-yyyy.to.date <- function(theDate) { <br><br>\n\n\u202fmyDate <- as.Date(theDate, format = \"%m-%d-%Y\") <br><br>\n\n\u202freturn(myDate) <br><br>\n\n} \n<\/p>\n\n\n\n<p><strong>2.4 \u2013\u202fFiles with packages and&nbsp;<\/strong><strong>addins<\/strong>&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>R and packages can be updated with the&nbsp;installr&nbsp;command on a (Windows) computer that already has R installed but when installing R on a brand new computer or a new operating system another method is needed&nbsp;<\/li><li>For installation on a brand new computer or a new operating system,&nbsp;It\u2019s&nbsp;very handy to keep a file with all packages and&nbsp;addins&nbsp;that you need and install them right after R has been installed for the first time. Below is a template file&nbsp;<\/li><\/ul>\n\n\n\n<p><p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\">\n################################################## <br><br>\n\n## Install Package Automatically &#8211; to run after R has been upgraded\/installed <br><br>\n\n## <br><br>\n\n## thertrader@gmail.com &#8211; Aug 2010&#8230; <br><br>\n\n################################################## <br><br>\n\n\u202f \n\ninstall.packages(c( <br><br>\n\n&#8220;data.table&#8221;, <br><br>\n\n&#8220;DEoptim&#8221;, <br><br>\n\n&#8220;devtools&#8221;, <br><br>\n\n&#8220;dplyr&#8221;, <br><br>\n\n&#8220;DT&#8221;, <br><br>\n\n&#8220;dygraphs&#8221;, <br><br>\n\n&#8220;ggplot2&#8221;, <br><br>\n\n&#8220;xts&#8221;, <br><br>\n\n&#8220;PerformanceAnalytics&#8221;)) <br><br>\n\n\u202f \n\ninstall.packages(&#8220;taskscheduleR&#8221;, repos = &#8220;https:\/\/www.datatailor.be\/rcube&#8221;, type = &#8220;source&#8221;) \n<\/p><\/p>\n\n\n\n<p><strong>3 \u2013 Syntax<\/strong>&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Place spaces around all infix operators (=, +, -, &lt;-, etc.).&nbsp;<\/li><li>Use &lt;-, not =, for assignment.&nbsp;<\/li><li>Use comments to mark off sections of code.&nbsp;<\/li><li>Comment your code with care. Comments should explain the why, not the what&nbsp;<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Each line of a comment should begin with the comment symbol and a single space&nbsp;<\/li><li>An opening curly brace should never go on its own line and should always be followed by a new line; a closing curly brace should always go on its own line, unless followed by else.&nbsp;<\/li><li>Always indent the code inside the curly braces.&nbsp;<\/li><li>Keep your lines less than 80&nbsp;characters.This&nbsp;is the amount that will fit comfortably on a printed page at a reasonable size. If you find you are running out of room, this is probably an indication that you should encapsulate some of the work in a separate function.&nbsp;<\/li><\/ul>\n\n\n\n<p><strong>4 \u2013 Miscellaneous<\/strong>&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Use RStudio&nbsp;<\/li><li>Use version control when you start sharing code. RStudio ships with integrated facilities to access&nbsp;GitHub&nbsp;and SVN&nbsp;<\/li><li>Keep track of versions (of data, of functions).&nbsp;<\/li><li>Always start with a clean environment instead of saving the workspace.&nbsp;<\/li><li>Keep track of session information in your project folder.&nbsp;<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Keep track of the memory used by your program.&nbsp;<\/li><li>Have someone else review your code: hence this document\u202f<img decoding=\"async\" alt=\"Shape ????\" src=\"blob:\/campus\/59327526-eb0a-430f-b7a1-bf60d52774da\">&nbsp;<\/li><\/ul>\n\n\n\n<p>This post has been written using my own experience and the following documents:&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/stat405.had.co.nz\/r-style.html\" target=\"_blank\" rel=\"noreferrer noopener\">R Style Guide<\/a>&nbsp;<\/li><li><a href=\"https:\/\/csgillespie.github.io\/efficientR\/\" target=\"_blank\" rel=\"noreferrer noopener\">Efficient R Programming<\/a>&nbsp;<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/stackoverflow.com\/questions\/2258092\/what-best-practices-do-you-use-for-programming-in-r\" target=\"_blank\" rel=\"noreferrer noopener\">What best practices do you use for programming in R? (StackOverflow)<\/a>&nbsp;<\/li><li><a href=\"https:\/\/journal.r-project.org\/archive\/2012-2\/RJournal_2012-2_Baaaath.pdf\" target=\"_blank\" rel=\"noreferrer noopener\">The State of Naming Conventions in R<\/a>&nbsp;<\/li><li><a href=\"https:\/\/swcarpentry.github.io\/r-novice-inflammation\/06-best-practices-R\/\" target=\"_blank\" rel=\"noreferrer noopener\">Best Practices for writing R<\/a>&nbsp;<\/li><li><a href=\"https:\/\/adv-r.had.co.nz\/Style.html\" target=\"_blank\" rel=\"noreferrer noopener\">Advanced R: Style Guide<\/a>&nbsp;<\/li><li><a href=\"https:\/\/www.r-bloggers.com\/consistent-naming-conventions-in-r\/\" target=\"_blank\" rel=\"noreferrer noopener\">Consistent Naming Conventions in R<\/a>&nbsp;<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/google.github.io\/styleguide\/Rguide.xml\" target=\"_blank\" rel=\"noreferrer noopener\">Google\u2019s R Style Guide<\/a>&nbsp;<\/li><\/ul>\n\n\n\n<p>Visit the The R Trader Blog <a href=\"https:\/\/www.thertrader.com\" target=\"_blank\" aria-label=\"undefined (opens in a new tab)\" rel=\"noreferrer noopener\">https:\/\/www.thertrader.com<\/a> to get additional tips and samples.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The R Trader shares best practices for coding R. Get practical tips on Naming conventions, Files organisation, Syntax and Miscellaneous items.<\/p>\n","protected":false},"author":186,"featured_media":52416,"comment_status":"closed","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[339,343,338,341,351,344,342],"tags":[4922,2533,2787,4921,487,6591,508,8016],"contributors-categories":[13704],"class_list":{"0":"post-52407","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science","8":"category-programing-languages","9":"category-ibkr-quant-news","10":"category-quant-development","11":"category-quant-europe","12":"category-quant-regions","13":"category-r-development","14":"tag-econometrics","15":"tag-ggplot2","16":"tag-performanceanalytics","17":"tag-quantitative-finance","18":"tag-r","19":"tag-rstats","20":"tag-rstudio","21":"tag-xts-package","22":"contributors-categories-the-r-trader"},"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>R Code \u2013 Best Practices | IBKR Quant<\/title>\n<meta name=\"description\" content=\"The R Trader shares best practices for coding R. Get practical tips on Naming conventions, Files organisation, Syntax and Misc. items.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/52407\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"R Code \u2013 Best Practices from The R Trader - IBKR Quant Blog\" \/>\n<meta property=\"og:description\" content=\"The R Trader shares best practices for coding R. Get practical tips on Naming conventions, Files organisation, Syntax and Misc. items.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-best-practices-r-trader\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-14T16:28:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-16T21:04:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/07\/best-practice.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"900\" \/>\n\t<meta property=\"og:image:height\" content=\"550\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Contributor Author\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Contributor Author\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t    \"@context\": \"https:\\\/\\\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"NewsArticle\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-best-practices-r-trader\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-best-practices-r-trader\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Contributor Author\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/e823e46b42ca381080387e794318a485\"\n\t            },\n\t            \"headline\": \"R Code \u2013 Best Practices\",\n\t            \"datePublished\": \"2020-07-14T16:28:44+00:00\",\n\t            \"dateModified\": \"2023-02-16T21:04:37+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-best-practices-r-trader\\\/\"\n\t            },\n\t            \"wordCount\": 570,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-best-practices-r-trader\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/07\\\/best-practice.jpg\",\n\t            \"keywords\": [\n\t                \"Econometrics\",\n\t                \"ggplot2\",\n\t                \"PerformanceAnalytics\",\n\t                \"Quantitative Finance\",\n\t                \"R\",\n\t                \"rstats\",\n\t                \"RStudio\",\n\t                \"XTS package\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"Programming Languages\",\n\t                \"Quant\",\n\t                \"Quant Development\",\n\t                \"Quant Europe\",\n\t                \"Quant Regions\",\n\t                \"R Development\"\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-best-practices-r-trader\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-best-practices-r-trader\\\/\",\n\t            \"name\": \"R Code \u2013 Best Practices from The R Trader - IBKR Quant Blog\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-best-practices-r-trader\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-best-practices-r-trader\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/07\\\/best-practice.jpg\",\n\t            \"datePublished\": \"2020-07-14T16:28:44+00:00\",\n\t            \"dateModified\": \"2023-02-16T21:04:37+00:00\",\n\t            \"description\": \"The R Trader shares best practices for coding R. Get practical tips on Naming conventions, Files organisation, Syntax and Misc. items.\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-best-practices-r-trader\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-code-best-practices-r-trader\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/07\\\/best-practice.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/07\\\/best-practice.jpg\",\n\t            \"width\": 900,\n\t            \"height\": 550,\n\t            \"caption\": \"Best Practice\"\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus US\",\n\t            \"description\": \"Financial Education from Interactive Brokers\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\",\n\t            \"name\": \"Interactive Brokers\",\n\t            \"alternateName\": \"IBKR\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\",\n\t                \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"width\": 669,\n\t                \"height\": 669,\n\t                \"caption\": \"Interactive Brokers\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\"\n\t            },\n\t            \"publishingPrinciples\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/about-ibkr-campus\\\/\",\n\t            \"ethicsPolicy\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/cyber-security-notice\\\/\"\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/e823e46b42ca381080387e794318a485\",\n\t            \"name\": \"Contributor Author\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/contributor-author\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"R Code \u2013 Best Practices | IBKR Quant","description":"The R Trader shares best practices for coding R. Get practical tips on Naming conventions, Files organisation, Syntax and Misc. items.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/52407\/","og_locale":"en_US","og_type":"article","og_title":"R Code \u2013 Best Practices from The R Trader - IBKR Quant Blog","og_description":"The R Trader shares best practices for coding R. Get practical tips on Naming conventions, Files organisation, Syntax and Misc. items.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-best-practices-r-trader\/","og_site_name":"IBKR Campus US","article_published_time":"2020-07-14T16:28:44+00:00","article_modified_time":"2023-02-16T21:04:37+00:00","og_image":[{"width":900,"height":550,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/07\/best-practice.jpg","type":"image\/jpeg"}],"author":"Contributor Author","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Contributor Author","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-best-practices-r-trader\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-best-practices-r-trader\/"},"author":{"name":"Contributor Author","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/e823e46b42ca381080387e794318a485"},"headline":"R Code \u2013 Best Practices","datePublished":"2020-07-14T16:28:44+00:00","dateModified":"2023-02-16T21:04:37+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-best-practices-r-trader\/"},"wordCount":570,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-best-practices-r-trader\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/07\/best-practice.jpg","keywords":["Econometrics","ggplot2","PerformanceAnalytics","Quantitative Finance","R","rstats","RStudio","XTS package"],"articleSection":["Data Science","Programming Languages","Quant","Quant Development","Quant Europe","Quant Regions","R Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-best-practices-r-trader\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-best-practices-r-trader\/","name":"R Code \u2013 Best Practices from The R Trader - IBKR Quant Blog","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-best-practices-r-trader\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-best-practices-r-trader\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/07\/best-practice.jpg","datePublished":"2020-07-14T16:28:44+00:00","dateModified":"2023-02-16T21:04:37+00:00","description":"The R Trader shares best practices for coding R. Get practical tips on Naming conventions, Files organisation, Syntax and Misc. items.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-best-practices-r-trader\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-code-best-practices-r-trader\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/07\/best-practice.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/07\/best-practice.jpg","width":900,"height":550,"caption":"Best Practice"},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.com\/campus\/#website","url":"https:\/\/ibkrcampus.com\/campus\/","name":"IBKR Campus US","description":"Financial Education from Interactive Brokers","publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.com\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ibkrcampus.com\/campus\/#organization","name":"Interactive Brokers","alternateName":"IBKR","url":"https:\/\/ibkrcampus.com\/campus\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","width":669,"height":669,"caption":"Interactive Brokers"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/"},"publishingPrinciples":"https:\/\/www.interactivebrokers.com\/campus\/about-ibkr-campus\/","ethicsPolicy":"https:\/\/www.interactivebrokers.com\/campus\/cyber-security-notice\/"},{"@type":"Person","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/e823e46b42ca381080387e794318a485","name":"Contributor Author","url":"https:\/\/www.interactivebrokers.com\/campus\/author\/contributor-author\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/07\/best-practice.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/52407","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/186"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=52407"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/52407\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/52416"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=52407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=52407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=52407"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=52407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}