Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't install the readxl package. error: format not a string literal and no format arguments [-Werror=format-security] #747

Closed
mikbrt opened this issue Jun 6, 2024 · 1 comment

Comments

@mikbrt
Copy link

mikbrt commented Jun 6, 2024

When I try to install the package using either:
install.packages("readxl") or devtools::install_cran("readxl")
I get the following output that results in no package installed:

Installing package into/home/username/R/x86_64-pc-linux-gnu-library/4.4’
(aslibis unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/readxl_1.4.3.tar.gz'
Content type 'application/x-gzip' length 2093488 bytes (2.0 MB)
==================================================
downloaded 2.0 MB

* installing *source* packagereadxl...
** packagereadxlsuccessfully unpacked and MD5 sums checked
** using staged installation
** libs
using C compiler: ‘gcc (Debian 12.2.0-14) 12.2.0using C++ compiler:g++ (Debian 12.2.0-14) 12.2.0g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -Iunix -I. -I'/home/username/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include' -I'/usr/lib/R/site-library/progress/include'    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/home/jranke/git/r-backports/bookworm/r-base-4.4.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2   -c cpp11.cpp -o cpp11.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -Iunix -I. -I'/home/username/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include' -I'/usr/lib/R/site-library/progress/include'    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/home/jranke/git/r-backports/bookworm/r-base-4.4.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2   -c XlsWorkBook.cpp -o XlsWorkBook.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -Iunix -I. -I'/home/username/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include' -I'/usr/lib/R/site-library/progress/include'    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/home/jranke/git/r-backports/bookworm/r-base-4.4.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2   -c XlsxWorkBook.cpp -o XlsxWorkBook.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -Iunix -I. -I'/home/username/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include' -I'/usr/lib/R/site-library/progress/include'    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/home/jranke/git/r-backports/bookworm/r-base-4.4.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2   -c zip.cpp -o zip.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -Iunix -I. -I'/home/username/R/x86_64-pc-linux-gnu-library/4.4/cpp11/include' -I'/usr/lib/R/site-library/progress/include'    -fvisibility=hidden -fpic  -g -O2 -ffile-prefix-map=/home/jranke/git/r-backports/bookworm/r-base-4.4.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2   -c Read.cpp -o Read.o
In file included from Spinner.h:3,
                 from XlsCellSet.h:4,
                 from SheetView.h:8,
                 from Read.cpp:1:
/usr/lib/R/site-library/progress/include/RProgress.h: In member functionvoid RProgress::RProgress::render()’:
/usr/lib/R/site-library/progress/include/RProgress.h:229:17: error: format not a string literal and no format arguments [-Werror=format-security]
  229 |         REprintf(str.c_str());
      |         ~~~~~~~~^~~~~~~~~~~~~
/usr/lib/R/site-library/progress/include/RProgress.h:231:16: error: format not a string literal and no format arguments [-Werror=format-security]
  231 |         Rprintf(str.c_str());
      |         ~~~~~~~^~~~~~~~~~~~~
/usr/lib/R/site-library/progress/include/RProgress.h: In member functionvoid RProgress::RProgress::clear_line(bool, int)’:
/usr/lib/R/site-library/progress/include/RProgress.h:272:15: error: format not a string literal and no format arguments [-Werror=format-security]
  272 |       REprintf(spaces);
      |       ~~~~~~~~^~~~~~~~
/usr/lib/R/site-library/progress/include/RProgress.h:274:14: error: format not a string literal and no format arguments [-Werror=format-security]
  274 |       Rprintf(spaces);
      |       ~~~~~~~^~~~~~~~
cc1plus: some warnings being treated as errors
make: *** [/usr/lib/R/etc/Makeconf:204: Read.o] Error 1
ERROR: compilation failed for packagereadxl* removing/home/username/R/x86_64-pc-linux-gnu-library/4.4/readxlThe downloaded source packages are in/tmp/Rtmp5P0Lvo/downloaded_packagesWarning message:
In install.packages("readxl") :
  installation of packagereadxlhad non-zero exit status

I tried setting these flags in my bash terminal to get around the issue but it didn't work:

export CXXFLAGS="-Wno-format-security"
export CFLAGS="-Wno-format-security"
@mikbrt
Copy link
Author

mikbrt commented Jun 6, 2024

Fixed the issue, there were a few lines wrong in the file: /usr/lib/R/site-library/progress/include/RProgress.h
Turns out it had nothing to do with the readxl package, but instead the R package "progress".

I changed lines 229, 231, 272, 274.
229 | REprintf(str.c_str()); -> REprintf("%s", str.c_str());
231 | Rprintf(str.c_str()); -> Rprintf("%s", str.c_str());
272 | REprintf(spaces); -> REprintf("%s", spaces);
274 | Rprintf(spaces); -> Rprintf("%s", spaces);

According to this reply in a thread for a different package, another solution would also be to install the new version of the progress package in R with command install.packages('progress'), which is probably a better than manually changing lines of code.

@mikbrt mikbrt closed this as completed Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant