{"id":5423,"date":"2014-04-04T11:47:35","date_gmt":"2014-04-04T10:47:35","guid":{"rendered":"http:\/\/www.walkingrandomly.com\/?p=5423"},"modified":"2014-04-04T11:47:35","modified_gmt":"2014-04-04T10:47:35","slug":"why-does-r-allow-us-to-exceed-array-bounds-here","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=5423","title":{"rendered":"Why does R allow us to exceed array bounds here?"},"content":{"rendered":"<p>A colleague recently sent me the following code snippet in R<\/p>\n<pre>\r\n> a=c(1,2,3,40)\r\n> b=a[1:10]\r\n> b\r\n[1]  1  2  3 40 NA NA NA NA NA NA\r\n<\/pre>\n<p>The fact that R didn&#8217;t issue a warning upset him since exceeding array bounds, as we did when we created b, is usually a programming error. <\/p>\n<p>I&#8217;m less concerned and simply file the above away in an area of my memory entitled &#8216;Odd things to remember about R&#8217; &#8212; I find that most programming languages have things that look odd when you encounter them for the first time.  With that said, I am curious as to why the designers of R thought that the above behaviour was a good idea.<\/p>\n<p>Does anyone have any insights here?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A colleague recently sent me the following code snippet in R > a=c(1,2,3,40) > b=a[1:10] > b [1] 1 2 3 40 NA NA NA NA NA NA The fact that R didn&#8217;t issue a warning upset him since exceeding array bounds, as we did when we created b, is usually a programming error. I&#8217;m [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[32,7,36],"tags":[],"class_list":["post-5423","post","type-post","status-publish","format-standard","hentry","category-open-source","category-programming","category-r"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-1pt","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/5423","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5423"}],"version-history":[{"count":1,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/5423\/revisions"}],"predecessor-version":[{"id":5425,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/5423\/revisions\/5425"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}