{"id":4457,"date":"2023-07-10T23:26:51","date_gmt":"2023-07-10T23:26:51","guid":{"rendered":"https:\/\/statorials.org\/pt\/r-excluir-arquivo\/"},"modified":"2023-07-10T23:26:51","modified_gmt":"2023-07-10T23:26:51","slug":"r-excluir-arquivo","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/r-excluir-arquivo\/","title":{"rendered":"Como excluir um arquivo usando r (com exemplo)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Voc\u00ea pode usar a seguinte sintaxe para excluir um arquivo em um local espec\u00edfico usando R:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define file to delete\n<\/span>this_file &lt;- \" <span style=\"color: #ff0000;\">C:\/Users\/bob\/Documents\/my_data_files\/soccer_data.csv<\/span> \"\n\n<span style=\"color: #008080;\">#delete file if it exists\n<\/span><span style=\"color: #008000;\">if<\/span> (file. <span style=\"color: #3366ff;\">exists<\/span> (this_file)) {\n  file. <span style=\"color: #3366ff;\">remove<\/span> (this_file)\n  cat(\" <span style=\"color: #ff0000;\">File deleted<\/span> \")\n} <span style=\"color: #008000;\">else<\/span> {\n  cat(\" <span style=\"color: #ff0000;\">No file found<\/span> \")\n}\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Esta sintaxe espec\u00edfica tenta excluir um arquivo chamado <strong>football_data.csv<\/strong> localizado na seguinte pasta:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>C:\/Users\/bob\/Documents\/my_data_files<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Se o arquivo existir, a fun\u00e7\u00e3o <strong>file.remove()<\/strong> exclui o arquivo e usa a fun\u00e7\u00e3o <a href=\"https:\/\/statorials.org\/pt\/r-gato-vs-pasta\/\" target=\"_blank\" rel=\"noopener\">cat<\/a> para exibir a mensagem \u201cArquivo exclu\u00eddo\u201d no console.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Se o arquivo n\u00e3o existir, a fun\u00e7\u00e3o cat exibe a mensagem \u201cNenhum arquivo encontrado\u201d no console.<\/span><\/p>\n<p> <span style=\"color: #000000;\">O exemplo a seguir mostra como usar essa sintaxe na pr\u00e1tica.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Exemplo: excluir um arquivo usando R<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Digamos que queremos excluir um arquivo chamado <strong>football_data.csv<\/strong> localizado na seguinte pasta:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>C:\/Users\/bob\/Documents\/my_data_files<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">A pasta atualmente cont\u00e9m tr\u00eas arquivos:<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-34893 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/delfile1.png\" alt=\"\" width=\"620\" height=\"468\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Podemos usar a seguinte sintaxe em R para excluir este arquivo, se ele existir:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define file to delete\n<\/span>this_file &lt;- \" <span style=\"color: #ff0000;\">C:\/Users\/bob\/Documents\/my_data_files\/soccer_data.csv<\/span> \"\n\n<span style=\"color: #008080;\">#delete file if it exists\n<\/span><span style=\"color: #008000;\">if<\/span> (file. <span style=\"color: #3366ff;\">exists<\/span> (this_file)) {\n  file. <span style=\"color: #3366ff;\">remove<\/span> (this_file)\n  cat(\" <span style=\"color: #ff0000;\">File deleted<\/span> \")\n} <span style=\"color: #008000;\">else<\/span> {\n  cat(\" <span style=\"color: #ff0000;\">No file found<\/span> \")\n}\n\nFile deleted\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>&nbsp;<\/strong> Recebemos a mensagem \u201cArquivo exclu\u00eddo\u201d que nos informa que o arquivo foi exclu\u00eddo.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Se retornarmos \u00e0 pasta onde existia o arquivo, veremos que ele foi exclu\u00eddo:<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-34894 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/delfile2.png\" alt=\"\" width=\"572\" height=\"478\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Para excluir outro arquivo, basta alterar o caminho do arquivo especificado na vari\u00e1vel chamada <strong>this_file<\/strong> .<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Recursos adicionais<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Os tutoriais a seguir explicam como realizar outras tarefas comuns em R:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><a href=\"https:\/\/statorials.org\/pt\/importar-csv-para-r\/\" target=\"_blank\" rel=\"noopener\">Como importar arquivos CSV para R<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/importar-excel-para-r\/\" target=\"_blank\" rel=\"noopener\">Como importar arquivos Excel para R<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/leia-o-arquivo-zip-em-r\/\" target=\"_blank\" rel=\"noopener\">Como importar arquivos Zip para R<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Voc\u00ea pode usar a seguinte sintaxe para excluir um arquivo em um local espec\u00edfico usando R: #define file to delete this_file &lt;- &#8221; C:\/Users\/bob\/Documents\/my_data_files\/soccer_data.csv &#8221; #delete file if it exists if (file. exists (this_file)) { file. remove (this_file) cat(&#8221; File deleted &#8220;) } else { cat(&#8221; No file found &#8220;) } Esta sintaxe espec\u00edfica tenta [&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-4457","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 excluir um arquivo usando R (com exemplo) - Statorials<\/title>\n<meta name=\"description\" content=\"Este tutorial explica como excluir arquivos em R, com um exemplo.\" \/>\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\/r-excluir-arquivo\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como excluir um arquivo usando R (com exemplo) - Statorials\" \/>\n<meta property=\"og:description\" content=\"Este tutorial explica como excluir arquivos em R, com um exemplo.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/r-excluir-arquivo\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-10T23:26:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/delfile1.png\" \/>\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\/r-excluir-arquivo\/\",\"url\":\"https:\/\/statorials.org\/pt\/r-excluir-arquivo\/\",\"name\":\"Como excluir um arquivo usando R (com exemplo) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-10T23:26:51+00:00\",\"dateModified\":\"2023-07-10T23:26:51+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Este tutorial explica como excluir arquivos em R, com um exemplo.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/r-excluir-arquivo\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/r-excluir-arquivo\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/r-excluir-arquivo\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como excluir um arquivo usando r (com exemplo)\"}]},{\"@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 excluir um arquivo usando R (com exemplo) - Statorials","description":"Este tutorial explica como excluir arquivos em R, com um exemplo.","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\/r-excluir-arquivo\/","og_locale":"pt_PT","og_type":"article","og_title":"Como excluir um arquivo usando R (com exemplo) - Statorials","og_description":"Este tutorial explica como excluir arquivos em R, com um exemplo.","og_url":"https:\/\/statorials.org\/pt\/r-excluir-arquivo\/","og_site_name":"Statorials","article_published_time":"2023-07-10T23:26:51+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/delfile1.png"}],"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\/r-excluir-arquivo\/","url":"https:\/\/statorials.org\/pt\/r-excluir-arquivo\/","name":"Como excluir um arquivo usando R (com exemplo) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-10T23:26:51+00:00","dateModified":"2023-07-10T23:26:51+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Este tutorial explica como excluir arquivos em R, com um exemplo.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/r-excluir-arquivo\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/r-excluir-arquivo\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/r-excluir-arquivo\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como excluir um arquivo usando r (com exemplo)"}]},{"@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\/4457","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=4457"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/4457\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=4457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=4457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=4457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}