After three years as an R-user I have a problem that haven’t been solved by looking around at stack overflow. Hence this is my first post. Please let me know if I need to be me more specific in the future.
I have a problem related to using the officer-package with R. Occasionally I work with qualitative data in NVivo which relies heavily on working with either docx or doc since NVivo autocodes via paragraph styles from MS-word/Office. I set out minimize the time spent to prepare docx-documents for NVivo via R and officer. After some initial steps I have a data frame with one column that contains separate paragraphs and one column containing paragraph style. I then create a new docx-object and apply the paragraph style and finish up by saving it. Basically this is what I’m doing:
#package
library(officer)
#Mock dataframe
a <- c("first paragraph text")
b <- c("Normal")
df <- data.frame(a,b)
#Create empty docx-object
clean_docx <- read_docx()
#Add paragraph from df[1,1] with style from df [1,2]
body_add_par(clean_docx,df[,1],df[,2])
#Save to document
print(clean_docx, target="test.docx")
When inspecting the new docx-document, everything looks as usual. The problem occurs when I try to import it to NVivo. I get an error message saying “Failed to import file. This file may contain more than 64K of text data in a single table row”.
When I re-save the documents as doc (manually in MS-Word) this problem do not occur. The same goes for copying the text from the document and saving it in a new docx-document (manually in MS-Word) – all paragraph styles created in R/officer are copied as well.
This problem do also occur when I export an empty docx-object to a docx-file. I noticed that size of the file (exported from R/officer) is 16 kb while an empty docx-document created manually in MS-Word is only 12 kb.
I have compared the docx-document exported from R/officer with docx-documents created manually in MS-word. I have not found any major differences (i.e. except author etc.). I tried also to convert the R/officer-generated document, using Compability Mode in Word but did not help either.
Do anybody have suggestions to solve this?