Andy
2023-Dec-30 12:12 UTC
[R] Help request: Parsing docx files for key words and appending to a spreadsheet
Hi Eric
Thanks for that. That seems to fix one problem (the lack of a
separator), but introduces a new one when I complete the function Calum
proposed:Error in docx_summary() : argument "x" is missing, with no
default
The whole code so far looks like this:
# Load libraries
library(tcltk)
library(tidyverse)
library(officer)
filepath <- setwd(tk_choose.dir())
filename <- "Now they want us to charge our electric cars from litter
bins.docx"
#full_filename <- paste0(filepath, filename) # Calum's original
suggestion
full_filename <- paste(filepath, filename, sep="/") # Eric's
proposed fix
#lets double check the file does exist! # The rest here is Calum's
suggestion
if (!file.exists(full_filename)) {
? message("File missing")
} else {
? content <- read_docx(full_filename)
? docx_summary()
? # this reads docx for the full filename and
? # passes it ( |> command) to the next line
? # which summarises it.
? # the result is saved in a data frame object
? # called content which we shall show some
? # heading into from
? head(content)
}
Running this, results in the error cited above.
Thanks as always :-)
On 30/12/2023 11:58, Eric Berger wrote:> full_filename <- paste(filepath, filename,sep="/")
[[alternative HTML version deleted]]
Eric Berger
2023-Dec-30 12:16 UTC
[R] Help request: Parsing docx files for key words and appending to a spreadsheet
docx_summary(content) You should read documentation e.g. ?docx_summary and check the examples section On Sat, Dec 30, 2023 at 2:12?PM Andy <phaedrusv at gmail.com> wrote:> Hi Eric > > Thanks for that. That seems to fix one problem (the lack of a separator), > but introduces a new one when I complete the function Calum proposed: > Error in docx_summary() : argument "x" is missing, with no default > > The whole code so far looks like this: > > > # Load libraries > library(tcltk) > library(tidyverse) > library(officer) > > filepath <- setwd(tk_choose.dir()) > > filename <- "Now they want us to charge our electric cars from litter > bins.docx" > #full_filename <- paste0(filepath, filename) # Calum's original suggestion > > full_filename <- paste(filepath, filename, sep="/") # Eric's proposed fix > > #lets double check the file does exist! # The rest here is Calum's > suggestion > if (!file.exists(full_filename)) { > message("File missing") > } else { > content <- read_docx(full_filename) > docx_summary() > # this reads docx for the full filename and > # passes it ( |> command) to the next line > # which summarises it. > # the result is saved in a data frame object > # called content which we shall show some > # heading into from > > head(content) > } > > > Running this, results in the error cited above. > > Thanks as always :-) > > > > > On 30/12/2023 11:58, Eric Berger wrote: > > full_filename <- paste(filepath, filename,sep="/") > > >[[alternative HTML version deleted]]
Andy
2023-Dec-30 12:18 UTC
[R] Help request: Parsing docx files for key words and appending to a spreadsheet
An update: Running this block of code:
# Load libraries
library(tcltk)
library(tidyverse)
library(officer)
filepath <- setwd(tk_choose.dir())
filename <- "Now they want us to charge our electric cars from litter
bins.docx"
#full_filename <- paste0(filepath, filename)
full_filename <- paste(filepath, filename, sep="/")
if (!file.exists(full_filename)) {
? message("File missing")
} else {
? content <- read_docx(full_filename) |>
??? docx_summary()
? # this reads docx for the full filename and
? # passes it ( |> command) to the next line
? # which summarises it.
? # the result is saved in a data frame object
? # called content which we shall show some
? # heading into from
? head(content)
}
Results in this error now:Error in x$doc_obj : $ operator is invalid for
atomic vectors
Thank you.
On 30/12/2023 12:12, Andy wrote:> Hi Eric
>
> Thanks for that. That seems to fix one problem (the lack of a
> separator), but introduces a new one when I complete the function
> Calum proposed:Error in docx_summary() : argument "x" is missing,
with
> no default
>
> The whole code so far looks like this:
>
>
> # Load libraries
> library(tcltk)
> library(tidyverse)
> library(officer)
>
> filepath <- setwd(tk_choose.dir())
>
> filename <- "Now they want us to charge our electric cars from
litter
> bins.docx"
> #full_filename <- paste0(filepath, filename) # Calum's original
suggestion
>
> full_filename <- paste(filepath, filename, sep="/") #
Eric's proposed fix
>
> #lets double check the file does exist! # The rest here is Calum's
> suggestion
> if (!file.exists(full_filename)) {
> ? message("File missing")
> } else {
> ? content <- read_docx(full_filename)
> ? docx_summary()
> ? # this reads docx for the full filename and
> ? # passes it ( |> command) to the next line
> ? # which summarises it.
> ? # the result is saved in a data frame object
> ? # called content which we shall show some
> ? # heading into from
>
> ? head(content)
> }
>
>
> Running this, results in the error cited above.
>
> Thanks as always :-)
>
>
>
>
> On 30/12/2023 11:58, Eric Berger wrote:
>> full_filename <- paste(filepath, filename,sep="/")
>
>
[[alternative HTML version deleted]]
Seemingly Similar Threads
- Help request: Parsing docx files for key words and appending to a spreadsheet
- Help request: Parsing docx files for key words and appending to a spreadsheet
- Help request: Parsing docx files for key words and appending to a spreadsheet
- Help request: Parsing docx files for key words and appending to a spreadsheet
- Help request: Parsing docx files for key words and appending to a spreadsheet