{"id":2039,"date":"2023-07-23T23:41:54","date_gmt":"2023-07-23T23:41:54","guid":{"rendered":"https:\/\/statorials.org\/pt\/o-objeto-do-tipo-de-fechamento-nao-e-ajustavel\/"},"modified":"2023-07-23T23:41:54","modified_gmt":"2023-07-23T23:41:54","slug":"o-objeto-do-tipo-de-fechamento-nao-e-ajustavel","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/o-objeto-do-tipo-de-fechamento-nao-e-ajustavel\/","title":{"rendered":"Como tratar em r: objeto do tipo \u201cfechamento\u201d n\u00e3o \u00e9 subdefin\u00edvel"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Um erro que voc\u00ea pode encontrar no R \u00e9:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>object of type 'closure' is not subsettable\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Este erro ocorre quando voc\u00ea tenta criar um subconjunto de uma fun\u00e7\u00e3o.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Em R \u00e9 poss\u00edvel criar subconjuntos de listas, vetores, matrizes e quadros de dados, mas uma fun\u00e7\u00e3o tem o tipo &#8220;fechamento&#8221; que n\u00e3o pode ser subconjunto.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Este tutorial explica exatamente como resolver esse erro.<\/span><\/p>\n<h3> <strong>Como reproduzir o erro<\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Suponha que criemos a seguinte fun\u00e7\u00e3o em R que pega cada valor de um vetor e o multiplica por 5:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#define function\n<span style=\"color: #000000;\">cool_function &lt;- <span style=\"color: #008000;\">function<\/span> (x) {\n  x &lt;- x*5\n  <span style=\"color: #008000;\">return<\/span> (x)\n}\n<\/span><\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Veja como poder\u00edamos usar essa fun\u00e7\u00e3o na pr\u00e1tica:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#define data\n<\/span>data &lt;- c(2, 3, 3, 4, 5, 5, 6, 9)\n\n<span style=\"color: #008080;\">#apply function to data\n<\/span>cool_function(data)\n\n[1] 10 15 15 20 25 25 30 45\n<\/span><\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Observe que cada valor do vetor original foi multiplicado por 5.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Agora suponha que tentamos subconjunto da fun\u00e7\u00e3o:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#attempt to get first element of function\n<span style=\"color: #000000;\">cool_function[1]\n\nError in cool_function[1]: object of type 'closure' is not subsettable\n<\/span><\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Recebemos um erro porque n\u00e3o \u00e9 poss\u00edvel criar um subconjunto de um objeto do tipo &#8220;fechamento&#8221; em R.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Podemos usar a seguinte sintaxe para verificar se a fun\u00e7\u00e3o \u00e9 de fato do tipo &#8216;fechamento&#8217;:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#print object type of function\n<span style=\"color: #000000;\">typeof(cool_function)\n\n[1] \u201cclosure\u201d\n<\/span><\/span><\/strong><\/span><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Mais exemplos de objetos \u201cClosure\u201d<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Toda fun\u00e7\u00e3o em R \u00e9 do tipo \u201cfechamento\u201d. Por exemplo, receber\u00edamos este erro se tent\u00e1ssemos subconjunto de qualquer fun\u00e7\u00e3o na base R:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#attempt to subset mean function<\/span>\nmean[1]\n\nError in mean[1]: object of type 'closure' is not subsettable\n\n<span style=\"color: #008080;\">#attempt to subset standard deviation function\n<\/span>sd[1]\n\nError in sd[1]: object of type 'closure' is not subsettable\n\n<span style=\"color: #008080;\">#attempt to subset table function\n<\/span>tabld[1]\n\nError in table[1]: object of type 'closure' is not subsettable\n<\/strong><\/span><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Como resolver o erro<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">A maneira de resolver esse erro \u00e9 simplesmente evitar a subdefini\u00e7\u00e3o de uma fun\u00e7\u00e3o.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Por exemplo, se quisermos aplicar nossa <strong>cool_function<\/strong> anterior apenas ao primeiro elemento de um vetor, podemos usar a seguinte sintaxe:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><b><span style=\"color: #008080;\">#apply function to just first element in vector<\/span>\ncool_function(data[1])\n\n[1] 10\n<\/b><\/span><\/pre>\n<p> <span style=\"color: #000000;\">N\u00e3o obtemos um erro porque subdefinimos o vetor em vez da fun\u00e7\u00e3o.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Ou poder\u00edamos aplicar <strong>cool_function<\/strong> a todo o vetor:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><b><span style=\"color: #008080;\">#apply function to every element in vector<\/span>\ncool_function(data)\n\n[1] 10 15 15 20 25 25 30 45<\/b><\/span><\/pre>\n<p> <span style=\"color: #000000;\">N\u00e3o estamos recebendo um erro porque n\u00e3o tentamos criar subconjuntos da fun\u00e7\u00e3o de forma alguma.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Recursos adicionais<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Os tutoriais a seguir explicam como resolver outros erros comuns em R:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/pt\/a-condicao-r-tem-comprimento-1-apenas-o-primeiro-elemento-sera-usado\/\" target=\"_blank\" rel=\"noopener\">Como corrigir: a condi\u00e7\u00e3o tem comprimento &gt; 1 e apenas o primeiro elemento ser\u00e1 usado<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/r-erro-dim-deve-ter-comprimento-positivo\/\" target=\"_blank\" rel=\"noopener\">Como corrigir em R: dim(X) deve ter comprimento positivo<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/r-valor-ausente-ou-verdadeiro-falso-necessario\/\" target=\"_blank\" rel=\"noopener\">Como corrigir em R: valor ausente onde verdadeiro\/falso \u00e9 necess\u00e1rio<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/nas-introduzido-por-coercao-em-r\/\" target=\"_blank\" rel=\"noopener\">Como corrigir: NAs introduzidos por coer\u00e7\u00e3o<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Um erro que voc\u00ea pode encontrar no R \u00e9: object of type &#8216;closure&#8217; is not subsettable Este erro ocorre quando voc\u00ea tenta criar um subconjunto de uma fun\u00e7\u00e3o. Em R \u00e9 poss\u00edvel criar subconjuntos de listas, vetores, matrizes e quadros de dados, mas uma fun\u00e7\u00e3o tem o tipo &#8220;fechamento&#8221; que n\u00e3o pode ser subconjunto. Este [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-2039","post","type-post","status-publish","format-standard","hentry","category-guia"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Como tratar em R: objeto do tipo \u201cfechamento\u201d n\u00e3o \u00e9 subconfigur\u00e1vel - Estatoriais<\/title>\n<meta name=\"description\" content=\"Este tutorial explica como lidar com o seguinte erro em R: o objeto do tipo &#039;fechamento&#039; n\u00e3o \u00e9 subconfigur\u00e1vel.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/pt\/o-objeto-do-tipo-de-fechamento-nao-e-ajustavel\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como tratar em R: objeto do tipo \u201cfechamento\u201d n\u00e3o \u00e9 subconfigur\u00e1vel - Estatoriais\" \/>\n<meta property=\"og:description\" content=\"Este tutorial explica como lidar com o seguinte erro em R: o objeto do tipo &#039;fechamento&#039; n\u00e3o \u00e9 subconfigur\u00e1vel.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/o-objeto-do-tipo-de-fechamento-nao-e-ajustavel\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-23T23:41:54+00:00\" \/>\n<meta name=\"author\" content=\"Dr. benjamim anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr. benjamim anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tempo estimado de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pt\/o-objeto-do-tipo-de-fechamento-nao-e-ajustavel\/\",\"url\":\"https:\/\/statorials.org\/pt\/o-objeto-do-tipo-de-fechamento-nao-e-ajustavel\/\",\"name\":\"Como tratar em R: objeto do tipo \u201cfechamento\u201d n\u00e3o \u00e9 subconfigur\u00e1vel - Estatoriais\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-23T23:41:54+00:00\",\"dateModified\":\"2023-07-23T23:41:54+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Este tutorial explica como lidar com o seguinte erro em R: o objeto do tipo &#39;fechamento&#39; n\u00e3o \u00e9 subconfigur\u00e1vel.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/o-objeto-do-tipo-de-fechamento-nao-e-ajustavel\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/o-objeto-do-tipo-de-fechamento-nao-e-ajustavel\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/o-objeto-do-tipo-de-fechamento-nao-e-ajustavel\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como tratar em r: objeto do tipo \u201cfechamento\u201d n\u00e3o \u00e9 subdefin\u00edvel\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/pt\/#website\",\"url\":\"https:\/\/statorials.org\/pt\/\",\"name\":\"Statorials\",\"description\":\"O seu guia para a literacia estat\u00edstica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/pt\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pt-PT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\",\"name\":\"Dr. benjamim anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr. benjamim anderson\"},\"description\":\"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais\",\"sameAs\":[\"https:\/\/statorials.org\/pt\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Como tratar em R: objeto do tipo \u201cfechamento\u201d n\u00e3o \u00e9 subconfigur\u00e1vel - Estatoriais","description":"Este tutorial explica como lidar com o seguinte erro em R: o objeto do tipo &#39;fechamento&#39; n\u00e3o \u00e9 subconfigur\u00e1vel.","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:\/\/statorials.org\/pt\/o-objeto-do-tipo-de-fechamento-nao-e-ajustavel\/","og_locale":"pt_PT","og_type":"article","og_title":"Como tratar em R: objeto do tipo \u201cfechamento\u201d n\u00e3o \u00e9 subconfigur\u00e1vel - Estatoriais","og_description":"Este tutorial explica como lidar com o seguinte erro em R: o objeto do tipo &#39;fechamento&#39; n\u00e3o \u00e9 subconfigur\u00e1vel.","og_url":"https:\/\/statorials.org\/pt\/o-objeto-do-tipo-de-fechamento-nao-e-ajustavel\/","og_site_name":"Statorials","article_published_time":"2023-07-23T23:41:54+00:00","author":"Dr. benjamim anderson","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"Dr. benjamim anderson","Tempo estimado de leitura":"2 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/pt\/o-objeto-do-tipo-de-fechamento-nao-e-ajustavel\/","url":"https:\/\/statorials.org\/pt\/o-objeto-do-tipo-de-fechamento-nao-e-ajustavel\/","name":"Como tratar em R: objeto do tipo \u201cfechamento\u201d n\u00e3o \u00e9 subconfigur\u00e1vel - Estatoriais","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-23T23:41:54+00:00","dateModified":"2023-07-23T23:41:54+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Este tutorial explica como lidar com o seguinte erro em R: o objeto do tipo &#39;fechamento&#39; n\u00e3o \u00e9 subconfigur\u00e1vel.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/o-objeto-do-tipo-de-fechamento-nao-e-ajustavel\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/o-objeto-do-tipo-de-fechamento-nao-e-ajustavel\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/o-objeto-do-tipo-de-fechamento-nao-e-ajustavel\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como tratar em r: objeto do tipo \u201cfechamento\u201d n\u00e3o \u00e9 subdefin\u00edvel"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/pt\/#website","url":"https:\/\/statorials.org\/pt\/","name":"Statorials","description":"O seu guia para a literacia estat\u00edstica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/pt\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pt-PT"},{"@type":"Person","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666","name":"Dr. benjamim anderson","image":{"@type":"ImageObject","inLanguage":"pt-PT","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr. benjamim anderson"},"description":"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais","sameAs":["https:\/\/statorials.org\/pt"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/2039","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/comments?post=2039"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/2039\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=2039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=2039"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=2039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}