Issue with staplr package in R: set_fields returns the error 'Error: All unnamed arguments must be length 1'

120 views Asked by At

I have been trying to generate a pdf file in R using the staplr package. However I have been running into issues whilst trying to run the example code. I keep getting an error (All unnamed arguments must be length 1) when trying to use the set_fields function.

library(staplr)
pdfFile = system.file('testForm.pdf',package = 'staplr')

# And do
fields = get_fields(pdfFile)
# You'll get a list of fields that the pdf contains 
# along with some additional information about the fields.

# You make modifications in any of the fields by
fields$TextField1$value = 'this is text'
set_fields(pdfFile, 'newFile.pdf', fields)

# This will create a filled pdf file

The get_fields function seems to work fine, I am using it in R and able to see that the field variable is updated with the new information. The issue is only when the set_fields function is applied.

I installed java using the code provided and installed rJava (install.packages("rJava")):

sudo apt update -y
sudo apt install -y openjdk-8-jdk openjdk-8-jre
sudo R CMD javareconf

I first installed the package in R using:

install.packages('staplr', dependencies = TRUE)

Uninstalled this version after is produced this error and tried:

devtools::install_github("pridiltal/staplr")

However the same issue keeps arising.

As part of my troubleshooting I tried to install pdftools using:

sudo apt-get install libpoppler-cpp-dev

I'm at a loss as to what to try next so any insight would be appreciated. Thanks!

The set_fields function should output the pdf with the updated fields. As I am using the exampled code I assumed there was no issue with the structure but perhaps related to how the dependent packages were installed.

1

There are 1 answers

3
Beginner On

I had a similar issue with a DIFFERENT function of the R package staplr, and I do not have the problem anymore.

I discovered that this library uses the program PDFtk (https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/).

So, I installed the program (It seems that after you install the program you need to set the path environments in the operating system, at least for Windows. I noticed that you are using Linux) (If you want to watch a video about how to do set the path environment with Windows, check this video: https://www.youtube.com/watch?time_continue=1&v=gb9e3m98avk&embeds_euri=https%3A%2F%2Fmail.google.com%2F&embeds_origin=https%3A%2F%2Fmail.google.com&feature=emb_logo) (If you want to know how to install PDFtk, check: https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/ ).

I also changed the R profile, or at least I believe that I did it, using the R command libpaths("folder where the R file and the PDF is located"). There are several questions about the R command libpaths in Stackoverflow, you can find them in this link:

Before these changes, I was getting several errors, among them "normalizePath:."

All these tips worked in Windows, so you would have to adapt them because you are using Linux.