{"id":124868,"date":"2022-02-18T12:52:10","date_gmt":"2022-02-18T17:52:10","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=124868"},"modified":"2022-11-21T09:51:55","modified_gmt":"2022-11-21T14:51:55","slug":"how-to-read-and-create-word-documents-in-r","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-read-and-create-word-documents-in-r\/","title":{"rendered":"How to Read and Create Word Documents in R"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"h-reading-and-creating-word-documents-in-r\"><strong>Reading and creating word documents in R<\/strong><\/h2>\n\n\n\n<p>In this post we\u2019ll talk about how to use R to read and create word files. We\u2019ll primarily be using R\u2019s&nbsp;<strong>officer<\/strong>&nbsp;package.&nbsp;<a href=\"https:\/\/theautomatic.net\/2019\/10\/14\/how-to-read-word-documents-with-python\/\">For reading data from Word Documents with Python, click here.<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-creating-word-reports-with-the-officer-package\"><strong>Creating Word reports with the officer package<\/strong><\/h2>\n\n\n\n<p>The first thing we need to do is to install the&nbsp;<strong>officer<\/strong>&nbsp;package.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\ninstall.packages(\"officer\")<\/code><\/pre>\n\n\n\n<p>We\u2019ll also be using the&nbsp;<strong>dplyr<\/strong>&nbsp;package, so you\u2019ll need to install that the same way if you don\u2019t have it already. Next, let\u2019s load each of these packages.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>library(officer)\nlibrary(dplyr)<\/code><\/pre>\n\n\n\n<p>Now, we\u2019ll get started creating a report! First, we will use the&nbsp;<strong>read_docx<\/strong>&nbsp;function to create an empty Word file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># create empty Word file\nsample_doc &lt;- read_docx()<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"adding-paragraphs\"><strong>Adding paragraphs<\/strong><\/h3>\n\n\n\n<p>Next, let\u2019s add a few sample paragraphs. We can do that using the&nbsp;<strong>body_add_par<\/strong>&nbsp;function like below. The syntax is similar to that of the&nbsp;<strong>tidyverse<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sample_doc &lt;- sample_doc %&gt;% body_add_par(\"This is the first paragraph\") \nsample_doc &lt;- sample_doc %&gt;% body_add_par(\"This is the second paragraph\")\nsample_doc &lt;- sample_doc %&gt;% body_add_par(\"This is the third paragraph\")<\/code><\/pre>\n\n\n\n<p>Now, we can add a table to our document using the&nbsp;<strong>body_add_table<\/strong>&nbsp;function. Before we do that, we just need to have a data frame ready, so we\u2019ll create a sample one like below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># create sample data frame\ndf &lt;- data.frame(a = 1:10, b = 11:20, c= 21:30)\n \n# add table containing the data frame's contents\nsample_doc &lt;- sample_doc %&gt;% body_add_table(df, style = \"table_template\")<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"adding-images-to-the-document\"><strong>Adding images to the document<\/strong><\/h3>\n\n\n\n<p>We can also add images to our Word Document. This is done by creating a temp file with an R plot and then adding the image to our document object. Though we\u2019re using base R for plotting here,&nbsp;<strong>ggplot<\/strong>&nbsp;could also be used.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>set.seed(0)\n \n# create a temp file\nsrc &lt;- tempfile(fileext = \".png\")\n \n# create PNG object\npng(filename = src, width = 4, height = 4, units = 'in', res = 400)\n \n# create plot\nplot(sample(100, 10))\n \n# save PNG file\ndev.off()\n \n# add PNG image to Word document\nsample_doc &lt;- sample_doc %&gt;% body_add_img(src = src, width = 4, height = 4, style = \"centered\")\n<\/code><\/pre>\n\n\n\n<p>Lastly, we can save our Word Document using&nbsp;<strong>print<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>print(sample_doc, target = \"sample_file.docx\")<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"how-to-modify-existing-word-documents\"><strong>How to modify existing Word Documents<\/strong><\/h3>\n\n\n\n<p>To modify existing Word Documents, all we need to change is to input the filename into&nbsp;<strong>read_docx<\/strong>. Then, we can continue modifying our Word Document object like we were previously.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sample_doc &lt;- read_docx(\"sample_file.docx\")\n \n# add another paragraph\nsample_doc &lt;- sample_doc %&gt;% body_add_par(\"This is another paragraph\")<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-read-word-documents-with-r\"><strong>How to read Word Documents with R<\/strong><\/h2>\n\n\n\n<p>What if we want to read in the Word Document we just created? We can do that using the same&nbsp;<strong>read_docx<\/strong>&nbsp;function like we did above to modify an existing file. Secondly, we use the&nbsp;<strong>docx_summary<\/strong>&nbsp;with this object to get the content within the file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sample_data &lt;- read_docx(\"sample_file.docx\")\n \ncontent &lt;- docx_summary(sample_data)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"640\" height=\"73\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/02\/read-word-document-in-r-the-automatic-net.png\" alt=\"\" class=\"wp-image-124917 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/02\/read-word-document-in-r-the-automatic-net.png 640w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/02\/read-word-document-in-r-the-automatic-net-300x34.png 300w\" data-sizes=\"(max-width: 640px) 100vw, 640px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 640px; aspect-ratio: 640\/73;\" \/><\/figure>\n\n\n\n<p><strong>docx_summary<\/strong>&nbsp;returns a dataframe with the content in the Word file, as can be seen above. For example, to get the text in the paragraph of the document, we just need to filter the content_type field on \u201cparagraph\u201d, like below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>paragraphs &lt;- content %&gt;% filter(content_type == \"paragraph\")\nparagraphs$text<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/02\/docx_summary-in-r-the-automatic-net.png\" alt=\"\" class=\"wp-image-124948 lazyload\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"extracting-tables-from-word-documents\"><strong>Extracting tables from Word Documents<\/strong><\/h3>\n\n\n\n<p>Now, let\u2019s extract the table from our document. We can do this similarly to the above in that we just need to filter content_type for \u201ctable cell\u201d:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>content %&gt;% filter(content_type == \"table cell\")<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"640\" height=\"105\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/02\/extract-table-from-word-document-in-r-the-automatic-net.png\" alt=\"\" class=\"wp-image-124952 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/02\/extract-table-from-word-document-in-r-the-automatic-net.png 640w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/02\/extract-table-from-word-document-in-r-the-automatic-net-300x49.png 300w\" data-sizes=\"(max-width: 640px) 100vw, 640px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 640px; aspect-ratio: 640\/105;\" \/><\/figure>\n\n\n\n<p>As you can see, the table\u2019s columns are stacked in a single column. We need to do a little transformation to get this result into the needed format.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>table_cells &lt;- content %&gt;% filter(content_type == \"table cell\")\ntable_data &lt;- table_cells %&gt;% filter(!is_header) %&gt;% select(row_id, cell_id, text)\n \n# split data into individual columns\nsplits &lt;- split(table_data, table_data$cell_id)\nsplits &lt;- lapply(splits, function(x) x$text)\n \n# combine columns back together in wide format\ntable_result &lt;- bind_cols(splits)\n \n# get table headers\ncols &lt;- table_cells %&gt;% filter(is_header)\nnames(table_result) &lt;- cols$text<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image img-twothird\"><img decoding=\"async\" width=\"323\" height=\"309\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/02\/read-table-from-word-document-with-r-the-automatic-net.png\" alt=\"\" class=\"wp-image-124956 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/02\/read-table-from-word-document-with-r-the-automatic-net.png 323w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/02\/read-table-from-word-document-with-r-the-automatic-net-300x287.png 300w\" data-sizes=\"(max-width: 323px) 100vw, 323px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 323px; aspect-ratio: 323\/309;\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p><strong>officer<\/strong>&nbsp;can also be used to interact with PowerPoint files, which we\u2019ll cover in a future post. That\u2019s all for now!&nbsp;<a href=\"https:\/\/twitter.com\/AutomaticSource\">Click here to follow my blog Twitter and get notified of new posts!<\/a>&nbsp;For more on&nbsp;<strong>officer<\/strong>, check out&nbsp;<a href=\"https:\/\/davidgohel.github.io\/officer\/index.html\">this link<\/a>.<\/p>\n\n\n\n<p><em>Visit <a href=\"https:\/\/theautomatic.net\/2020\/07\/21\/how-to-read-and-create-word-documents-in-r\/\">TheAutomatic.net<\/a> for additional insight on this topic.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post we\u2019ll talk about how to use R to read and create word files. We\u2019ll primarily be using R\u2019s officer package<\/p>\n","protected":false},"author":388,"featured_media":80184,"comment_status":"closed","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[339,343,338,341,352,344,342],"tags":[806,487,6591,508],"contributors-categories":[13695],"class_list":{"0":"post-124868","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-north-america","12":"category-quant-regions","13":"category-r-development","14":"tag-data-science","15":"tag-r","16":"tag-rstats","17":"tag-rstudio","18":"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>How to Read and Create Word Documents in R | IBKR Quant<\/title>\n<meta name=\"description\" content=\"In this post we\u2019ll talk about how to use R to read and create word files. We\u2019ll primarily be using R\u2019s officer package\" \/>\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\/124868\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Read and Create Word Documents in R | IBKR Quant Blog\" \/>\n<meta property=\"og:description\" content=\"In this post we\u2019ll talk about how to use R to read and create word files. We\u2019ll primarily be using R\u2019s officer package\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-read-and-create-word-documents-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-18T17:52:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-21T14:51:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2021\/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=\"4 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\\\/how-to-read-and-create-word-documents-in-r\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-read-and-create-word-documents-in-r\\\/\"\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\": \"How to Read and Create Word Documents in R\",\n\t            \"datePublished\": \"2022-02-18T17:52:10+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:51:55+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-read-and-create-word-documents-in-r\\\/\"\n\t            },\n\t            \"wordCount\": 532,\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\\\/how-to-read-and-create-word-documents-in-r\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2021\\\/03\\\/R-programing.jpg\",\n\t            \"keywords\": [\n\t                \"Data Science\",\n\t                \"R\",\n\t                \"rstats\",\n\t                \"RStudio\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"Programming Languages\",\n\t                \"Quant\",\n\t                \"Quant Development\",\n\t                \"Quant North America\",\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\\\/how-to-read-and-create-word-documents-in-r\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-read-and-create-word-documents-in-r\\\/\",\n\t            \"name\": \"How to Read and Create Word Documents in R | 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\\\/how-to-read-and-create-word-documents-in-r\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/how-to-read-and-create-word-documents-in-r\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2021\\\/03\\\/R-programing.jpg\",\n\t            \"datePublished\": \"2022-02-18T17:52:10+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:51:55+00:00\",\n\t            \"description\": \"In this post we\u2019ll talk about how to use R to read and create word files. We\u2019ll primarily be using R\u2019s officer package\",\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\\\/how-to-read-and-create-word-documents-in-r\\\/\"\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\\\/how-to-read-and-create-word-documents-in-r\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2021\\\/03\\\/R-programing.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2021\\\/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":"How to Read and Create Word Documents in R | IBKR Quant","description":"In this post we\u2019ll talk about how to use R to read and create word files. We\u2019ll primarily be using R\u2019s officer package","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\/124868\/","og_locale":"en_US","og_type":"article","og_title":"How to Read and Create Word Documents in R | IBKR Quant Blog","og_description":"In this post we\u2019ll talk about how to use R to read and create word files. We\u2019ll primarily be using R\u2019s officer package","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-read-and-create-word-documents-in-r\/","og_site_name":"IBKR Campus US","article_published_time":"2022-02-18T17:52:10+00:00","article_modified_time":"2022-11-21T14:51:55+00:00","og_image":[{"width":900,"height":550,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2021\/03\/R-programing.jpg","type":"image\/jpeg"}],"author":"Andrew Treadway","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Andrew Treadway","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-read-and-create-word-documents-in-r\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-read-and-create-word-documents-in-r\/"},"author":{"name":"Andrew Treadway","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/d4018570a16fb867f1c08412fc9c64bc"},"headline":"How to Read and Create Word Documents in R","datePublished":"2022-02-18T17:52:10+00:00","dateModified":"2022-11-21T14:51:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-read-and-create-word-documents-in-r\/"},"wordCount":532,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-read-and-create-word-documents-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2021\/03\/R-programing.jpg","keywords":["Data Science","R","rstats","RStudio"],"articleSection":["Data Science","Programming Languages","Quant","Quant Development","Quant North America","Quant Regions","R Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-read-and-create-word-documents-in-r\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-read-and-create-word-documents-in-r\/","name":"How to Read and Create Word Documents in R | IBKR Quant Blog","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-read-and-create-word-documents-in-r\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-read-and-create-word-documents-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2021\/03\/R-programing.jpg","datePublished":"2022-02-18T17:52:10+00:00","dateModified":"2022-11-21T14:51:55+00:00","description":"In this post we\u2019ll talk about how to use R to read and create word files. We\u2019ll primarily be using R\u2019s officer package","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-read-and-create-word-documents-in-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-read-and-create-word-documents-in-r\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2021\/03\/R-programing.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2021\/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\/2021\/03\/R-programing.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/124868","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=124868"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/124868\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/80184"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=124868"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=124868"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=124868"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=124868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}