{"id":195963,"date":"2023-09-08T10:26:09","date_gmt":"2023-09-08T14:26:09","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=195963"},"modified":"2023-09-08T17:26:19","modified_gmt":"2023-09-08T21:26:19","slug":"r-how-to-create-delete-move-and-more-with-files","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-how-to-create-delete-move-and-more-with-files\/","title":{"rendered":"R: How to Create, Delete, Move, and More with Files"},"content":{"rendered":"\n<p>Though Python is usually thought of over R for doing system administration tasks, R is actually quite useful in this regard. In this post we\u2019re going to talk about using R to create, delete, move, and obtain information on files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-to-get-and-change-the-current-working-directory\"><strong>How to get and change the current working directory<\/strong><\/h2>\n\n\n\n<p>Before working with files, it\u2019s usually a good idea to first know what directory you\u2019re working in. The working directory is the folder that any files you create or refer to without explicitly spelling out the full path fall within. In R, you can figure this out with the&nbsp;<strong>getwd<\/strong>&nbsp;function. To change this directory, you can use the aptly named&nbsp;<strong>setwd<\/strong>&nbsp;function.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># get current working directory\ngetwd()\n \n# set working directory\nsetwd(\"C:\/Users\")<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Creating Files and Directories<\/strong><\/h2>\n\n\n\n<p>A new folder, or directory, can be created in R using the&nbsp;<strong>dir.create<\/strong>&nbsp;function, like this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">dir.create(\"new_folder\")<\/pre>\n\n\n\n<p>You just need to replace \u201cnew_folder\u201d with whatever name you choose. If you don\u2019t write out the full path of this new directory, it will get created into whatever the current working directory is i.e. the value of&nbsp;<strong>getwd()<\/strong>.<\/p>\n\n\n\n<p>Similarly, creating a blank file can be done with&nbsp;<strong>file.create<\/strong>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">file.create(\"new_text_file.txt\")\nfile.create(\"new_word_file.docx\")\nfile.create(\"new_csv_file.csv\")<\/pre>\n\n\n\n<p>With this in mind, creating lots of files quickly is made easy. For example, the one-liner below will create 100 empty text files:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sapply(paste0(\"file\", 1:100, \".txt\"), file.create)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Copying a file \/ folder<\/strong><\/h2>\n\n\n\n<p>Copying a file can be done using&nbsp;<strong>file.copy<\/strong>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">file.copy(\"source_file.txt\", \"destination_folder\")<\/pre>\n\n\n\n<p>With&nbsp;<strong>file.copy<\/strong>, the first parameter is the name of the file to be copied; the second is the destination folder that you want to copy the file to. If the file copies successfully, the function will return TRUE \u2014 otherwise, it returns FALSE.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to list all the files in a directory<\/strong><\/h2>\n\n\n\n<p>The simplest way of listing all the files in a directory with R is by calling&nbsp;<strong>list.files<\/strong>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># list all files in current directory\nlist.files()\n \n# list all files in another directory\nlist.files(\"C:\/path\/to\/somewhere\/else\")<\/pre>\n\n\n\n<p>Calling&nbsp;<strong>list.files<\/strong>&nbsp;with no additional parameters will only list the files and folders directly within the directory \u2014 i.e. it doesn\u2019t list the files within any sub-folder unless you tell it to do so. This can be done like this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">list.files(\"C:\/path\/to\/somewhere\/else\", recursive = TRUE)<\/pre>\n\n\n\n<p>Note, adding the \u201crecursive = TRUE\u201d flag may cause the function to run for a longer period of time if the directory has a large number of sub-folders and files (e.g. running&nbsp;<strong>list.files(\u201cC:\/\u201d, recursive = TRUE)<\/strong>).<\/p>\n\n\n\n<p>An additional point \u2014 running default&nbsp;<strong>list.files<\/strong>&nbsp;doesn\u2019t list the full path names of the files. We can set the parameter, full.names, to TRUE to get the full path names.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">list.files(\"C:\/path\/to\/somewhere\/else\", full.names = TRUE, recursive = TRUE)<\/pre>\n\n\n\n<p><strong>list.files<\/strong>&nbsp;can also apply a filter internally to the files you want to list. For instance, the R code below will list all of the CSV files in a directory (similar to \u201cls | grep .csv\u201d in Linux)<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># list all CSV files non-recursively\nlist.files(pattern = \".csv\")\n \n# list all CSV files recursively through each sub-folder\nlist.files(pattern = \".csv\", recursive = TRUE)<\/pre>\n\n\n\n<p>The above logic can be really useful if you want to read in all of the CSV files within a given directory. For instance, suppose you have a list of CSV\u2019s in a folder, and you want to produce a single data frame (provided they each have the same layout) from all the files. You can accomplish this in a couple lines of code:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># read in all the CSV files\nall_data_frames &lt;- lapply(list.files(pattern = \".csv\"), read.csv)\n \n# stack all data frames together\nsingle_data_frame &lt;- Reduce(rbind, all_data_frames)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to get created \/ modified times and other details about files<\/strong><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\"><strong><u>fileSnapshot<\/u><\/strong><\/h4>\n\n\n\n<p>Another way of getting the files in a directory is using the function,&nbsp;<strong>fileSnapshot<\/strong>.&nbsp;<strong>fileSnapshot<\/strong>&nbsp;will also give you additional details about the files. This function returns a list of objects.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># get file snapshot of current directory\nsnapshot &lt;- fileSnapshot()\n \n# or file snapshot of another directory\nsnapshot &lt;- fileSnapshot(\"C:\/some\/other\/directory\")<\/pre>\n\n\n\n<p>fileSnapshot returns a list, which here we will just call \u201csnapshot\u201d. The most useful piece of information can be garnered from this by referencing \u201cinfo\u201d:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">snapshot$info<\/pre>\n\n\n\n<p>Here, snapshot$info is a data frame showing information about the files in the input folder parameter. Its headers include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>size ==&gt; size of file<\/li>\n\n\n\n<li>isdir ==&gt; is file a directory? ==&gt; TRUE or FALSE<\/li>\n\n\n\n<li>mode ==&gt; the file permissions in&nbsp;<a href=\"https:\/\/permissions-calculator.org\/\">octal<\/a><\/li>\n\n\n\n<li>mtime ==&gt; last modified time stamp<\/li>\n\n\n\n<li>ctime ==&gt; time stamp created<\/li>\n\n\n\n<li>atime ==&gt; time stamp last accessed<\/li>\n\n\n\n<li>exe ==&gt; type of executable (or \u201cno\u201d if not an executable)<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong><u>file.info<\/u><\/strong><\/h4>\n\n\n\n<p><strong>file.info<\/strong>&nbsp;is similar to&nbsp;<strong>fileSnapshot<\/strong>, except that it returns a single record of information corresponding to an input file. For instance, the code below will return the fields above (size, isdir, mode, mtime etc.) for the specific file, \u201csome_file.csv\u201d:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">file.info(\"some_file.csv\")<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong><u>file.ctime<\/u><\/strong><\/h4>\n\n\n\n<p>If you want to get just the created time stamp of a file, call&nbsp;<strong>file.ctime<\/strong>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">file.ctime(\"C:\/path\/to\/file\/some_file.txt\")<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong><u>file.mtime<\/u><\/strong><\/h4>\n\n\n\n<p>Getting the last modified time stamp is similar to above, except we use&nbsp;<strong>file.mtime<\/strong>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">file.mtime(\"C:\/path\/to\/file\/some_file.txt\")<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to delete files<\/strong><\/h2>\n\n\n\n<p>Files can be deleted with R using&nbsp;<strong>unlink<\/strong>. Deleting a single file is as simple as passing the file\u2019s name to this function.<\/p>\n\n\n\n<p>To delete a directory, you have to add the parameter&nbsp;<strong>recursive = TRUE<\/strong>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># delete a file\nunlink(\"some_file.csv\")\n \n# delete another file\nfile.remove(\"some_other_file.csv\")\n \n# delete a directory -- must add recursive = TRUE\nunlink(\"some_directory\", recursive = TRUE)<\/pre>\n\n\n\n<p>With&nbsp;<strong>unlink<\/strong>, we can delete the 100 text files we created above with&nbsp;<strong>file.create<\/strong>&nbsp;\u2014 also in just one line of code.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sapply(paste0(\"file\", 1:100, \".txt\"), unlink)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to check if a file or directory exists<\/strong><\/h2>\n\n\n\n<p>You can check if a file exists, using the&nbsp;<strong>file.exists<\/strong>&nbsp;function.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># check if a file exists\nfile.exists(\"C:\/path\/to\/file\/some_file.txt\")\n \n# check if a folder exists\nfile.exists(\"C:\/path\/to\/file\/some_folder\")\n \n# alternatively, check if a folder exists with dir.exists\ndir.exists(\"C:\/path\/to\/file\/some_folder\")<\/pre>\n\n\n\n<p>Running&nbsp;<strong>file.exists<\/strong>&nbsp;will return TRUE whether an existing file is a directory or not, whereas&nbsp;<strong>dir.exists<\/strong>&nbsp;will return TRUE if and only if the input value exists and is a directory.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to get the base name of a file<\/strong><\/h2>\n\n\n\n<p>Getting the base name of a file can be done using the&nbsp;<strong>basename<\/strong>&nbsp;function:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">basename(\"C:\/path\/to\/file.txt\")<\/pre>\n\n\n\n<p>The above code will return&nbsp;<strong>\u201cfile.txt\u201d<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to get the directory name of a file<\/strong><\/h2>\n\n\n\n<p>Tweaking the code above, we can get the directory of a file like this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">dirname(\"C:\/path\/to\/file.txt\")<\/pre>\n\n\n\n<p>This will return&nbsp;<strong>\u201cC:\/path\/to\u201d<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to get a file\u2019s extension<\/strong><\/h2>\n\n\n\n<p><strong><\/strong><\/p>\n\n\n\n<p>Getting a file\u2019s extension can be done using the&nbsp;<strong>file_ext<\/strong>&nbsp;function from the&nbsp;<strong>tools<\/strong>&nbsp;package.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">library(tools)\n \nfile_ext(\"C:\/path\/to\/file.txt\") # returns \"txt\"\n \nfile_ext(\"C:\/path\/to\/file.csv\") # returns \"csv\"<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to physically open a file<\/strong><\/h2>\n\n\n\n<p><strong><\/strong><\/p>\n\n\n\n<p>To physically open, or launch, a file, use the&nbsp;<strong>shell.exec<\/strong>&nbsp;or&nbsp;<strong>file.show<\/strong>&nbsp;functions:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># use shell.exec...\nshell.exec(\"C:\/path\/to\/file\/some_file.txt\")\n \n# or file.show to launch a file\nfile.show(\"C:\/path\/to\/file\/some_file.txt\")<\/pre>\n\n\n\n<p>This can be really handy if you\u2019re modifying a section of code that writes over the same file, and you want to open it to check some results without having to manually do so.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to open a file selection window<\/strong><\/h2>\n\n\n\n<p><strong><\/strong><\/p>\n\n\n\n<p>To open a file selection window, you can run&nbsp;<strong>file.choose()<\/strong>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">file.choose()<\/pre>\n\n\n\n<p>Running this command will return the name of the file selected by the user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to move a file<\/strong><\/h2>\n\n\n\n<p><strong><\/strong><\/p>\n\n\n\n<p>As of this writing, there is not a built-in base R function to directly move a file from one place to another, but this can be accomplished using the&nbsp;<strong>filesstrings<\/strong>&nbsp;package, and its function&nbsp;<strong>file.move<\/strong>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">library(filesstrings)\n \nfile.move(\"C:\/path\/to\/file\/some_file.txt\", \"C:\/some\/other\/path\")<\/pre>\n\n\n\n<p>Here, the first argument is the name of the file you want to move. The second argument is the destination directory<\/p>\n\n\n\n<p><em>Originally posted on <a href=\"https:\/\/theautomatic.net\/2018\/07\/11\/manipulate-files-r\/\">TheAutomatic.net<\/a>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post we\u2019re going to talk about using R to create, delete, move, and obtain information on files.<\/p>\n","protected":false},"author":388,"featured_media":186467,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[339,343,338,341,342],"tags":[806,487,6591],"contributors-categories":[13695],"class_list":{"0":"post-195963","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-r-development","12":"tag-data-science","13":"tag-r","14":"tag-rstats","15":"contributors-categories-theautomatic-net"},"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: How to Create, Delete, Move, and More with Files<\/title>\n<meta name=\"description\" content=\"In this post we\u2019re going to talk about using R to create, delete, move, and obtain information on files.\" \/>\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\/195963\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"R: How to Create, Delete, Move, and More with Files | IBKR Campus US\" \/>\n<meta property=\"og:description\" content=\"In this post we\u2019re going to talk about using R to create, delete, move, and obtain information on files.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-how-to-create-delete-move-and-more-with-files\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2023-09-08T14:26:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-08T21:26:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/r-programing.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=\"Andrew Treadway\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andrew Treadway\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 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-how-to-create-delete-move-and-more-with-files\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-how-to-create-delete-move-and-more-with-files\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Andrew Treadway\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/d4018570a16fb867f1c08412fc9c64bc\"\n\t            },\n\t            \"headline\": \"R: How to Create, Delete, Move, and More with Files\",\n\t            \"datePublished\": \"2023-09-08T14:26:09+00:00\",\n\t            \"dateModified\": \"2023-09-08T21:26:19+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-how-to-create-delete-move-and-more-with-files\\\/\"\n\t            },\n\t            \"wordCount\": 1140,\n\t            \"commentCount\": 0,\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-how-to-create-delete-move-and-more-with-files\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/03\\\/r-programing.jpg\",\n\t            \"keywords\": [\n\t                \"Data Science\",\n\t                \"R\",\n\t                \"rstats\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"Programming Languages\",\n\t                \"Quant\",\n\t                \"Quant Development\",\n\t                \"R Development\"\n\t            ],\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"CommentAction\",\n\t                    \"name\": \"Comment\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-how-to-create-delete-move-and-more-with-files\\\/#respond\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-how-to-create-delete-move-and-more-with-files\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-how-to-create-delete-move-and-more-with-files\\\/\",\n\t            \"name\": \"R: How to Create, Delete, Move, and More with Files | IBKR Campus US\",\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-how-to-create-delete-move-and-more-with-files\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/r-how-to-create-delete-move-and-more-with-files\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/03\\\/r-programing.jpg\",\n\t            \"datePublished\": \"2023-09-08T14:26:09+00:00\",\n\t            \"dateModified\": \"2023-09-08T21:26:19+00:00\",\n\t            \"description\": \"In this post we\u2019re going to talk about using R to create, delete, move, and obtain information on files.\",\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-how-to-create-delete-move-and-more-with-files\\\/\"\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-how-to-create-delete-move-and-more-with-files\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/03\\\/r-programing.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/03\\\/r-programing.jpg\",\n\t            \"width\": 900,\n\t            \"height\": 550,\n\t            \"caption\": \"R Programming\"\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\\\/d4018570a16fb867f1c08412fc9c64bc\",\n\t            \"name\": \"Andrew Treadway\",\n\t            \"description\": \"Andrew Treadway currently works as a Senior Data Scientist, and has experience doing analytics, software automation, and ETL. He completed a master\u2019s degree in computer science \\\/ machine learning, and an undergraduate degree in pure mathematics. Connect with him on LinkedIn: https:\\\/\\\/www.linkedin.com\\\/in\\\/andrew-treadway-a3b19b103\\\/In addition to TheAutomatic.net blog, he also teaches in-person courses on Python and R through my NYC meetup: more details.\",\n\t            \"sameAs\": [\n\t                \"https:\\\/\\\/theautomatic.net\\\/about-me\\\/\"\n\t            ],\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/andrewtreadway\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"R: How to Create, Delete, Move, and More with Files","description":"In this post we\u2019re going to talk about using R to create, delete, move, and obtain information on files.","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\/195963\/","og_locale":"en_US","og_type":"article","og_title":"R: How to Create, Delete, Move, and More with Files | IBKR Campus US","og_description":"In this post we\u2019re going to talk about using R to create, delete, move, and obtain information on files.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-how-to-create-delete-move-and-more-with-files\/","og_site_name":"IBKR Campus US","article_published_time":"2023-09-08T14:26:09+00:00","article_modified_time":"2023-09-08T21:26:19+00:00","og_image":[{"width":900,"height":550,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/r-programing.jpg","type":"image\/jpeg"}],"author":"Andrew Treadway","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Andrew Treadway","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-how-to-create-delete-move-and-more-with-files\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-how-to-create-delete-move-and-more-with-files\/"},"author":{"name":"Andrew Treadway","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/d4018570a16fb867f1c08412fc9c64bc"},"headline":"R: How to Create, Delete, Move, and More with Files","datePublished":"2023-09-08T14:26:09+00:00","dateModified":"2023-09-08T21:26:19+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-how-to-create-delete-move-and-more-with-files\/"},"wordCount":1140,"commentCount":0,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-how-to-create-delete-move-and-more-with-files\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/r-programing.jpg","keywords":["Data Science","R","rstats"],"articleSection":["Data Science","Programming Languages","Quant","Quant Development","R Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-how-to-create-delete-move-and-more-with-files\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-how-to-create-delete-move-and-more-with-files\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-how-to-create-delete-move-and-more-with-files\/","name":"R: How to Create, Delete, Move, and More with Files | IBKR Campus US","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-how-to-create-delete-move-and-more-with-files\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-how-to-create-delete-move-and-more-with-files\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/r-programing.jpg","datePublished":"2023-09-08T14:26:09+00:00","dateModified":"2023-09-08T21:26:19+00:00","description":"In this post we\u2019re going to talk about using R to create, delete, move, and obtain information on files.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-how-to-create-delete-move-and-more-with-files\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/r-how-to-create-delete-move-and-more-with-files\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/r-programing.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/r-programing.jpg","width":900,"height":550,"caption":"R Programming"},{"@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\/d4018570a16fb867f1c08412fc9c64bc","name":"Andrew Treadway","description":"Andrew Treadway currently works as a Senior Data Scientist, and has experience doing analytics, software automation, and ETL. He completed a master\u2019s degree in computer science \/ machine learning, and an undergraduate degree in pure mathematics. Connect with him on LinkedIn: https:\/\/www.linkedin.com\/in\/andrew-treadway-a3b19b103\/In addition to TheAutomatic.net blog, he also teaches in-person courses on Python and R through my NYC meetup: more details.","sameAs":["https:\/\/theautomatic.net\/about-me\/"],"url":"https:\/\/www.interactivebrokers.com\/campus\/author\/andrewtreadway\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/r-programing.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/195963","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\/388"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=195963"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/195963\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/186467"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=195963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=195963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=195963"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=195963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}