ropensci / readODS

Read ODS (OpenDocument Spreadsheet) into R as data frame. Also support writing data frame into ODS file.
https://docs.ropensci.org/readODS/
Other
55 stars 22 forks source link

Installing readODS from CRAN failed :write_sheet_file_.cpp:158:21: error: invalid use of incomplete type ‘struct SEXPREC’ #174

Closed xning closed 1 year ago

xning commented 1 year ago

The error messages as follows:

write_sheet_file_.cpp: In function ‘cpp11::r_string write_sheet_file_list_(const std::string&, const cpp11::list_of<cpp11::data_frame>&, const std::string&, bool, bool, bool, bool, const std::string&, const std::string&)’:
write_sheet_file_.cpp:158:21: error: invalid use of incomplete type ‘struct SEXPREC’
  158 |         write_df(x[i], sheet_names[i], row_names, col_names, na_as_string, padding, xml_file);
      |                     ^
In file included from /usr/share/R/library/cpp11/include/cpp11/R.hpp:13,
                 from /usr/share/R/library/cpp11/include/cpp11.hpp:3,
                 from write_sheet_file_.h:3,
                 from write_sheet_file_.cpp:1:
/usr/include/R/Rinternals.h:180:16: note: forward declaration of ‘struct SEXPREC’
  180 | typedef struct SEXPREC *SEXP;
      |                ^~~~~~~
write_sheet_file_.cpp:158:21: error: invalid initialization of reference of type ‘const cpp11::data_frame&’ from expression of type ‘SEXPREC’
  158 |         write_df(x[i], sheet_names[i], row_names, col_names, na_as_string, padding, xml_file);
      |                  ~~~^
write_sheet_file_.cpp:54:40: note: in passing argument 1 of ‘void write_df(const cpp11::data_frame&, const std::string&, bool, bool, bool, bool, std::ofstream&)’
   54 | void write_df(const cpp11::data_frame& x, const std::string& sheet_name, const bool row_names, const bool col_names,
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~^
make: *** [/usr/lib64/R/etc/Makeconf:200: write_sheet_file_.o] Error 1
ERROR: compilation failed for package ‘readODS’
chainsawriot commented 1 year ago

sessionInfo() ?

xning commented 1 year ago

sessionInfo() ?

> sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Fedora Linux 38 (Workstation Edition)

Matrix products: default
BLAS/LAPACK: FlexiBLAS OPENBLAS-OPENMP;  LAPACK version 3.11.0

locale:
 [1] LC_CTYPE=en_US.utf8       LC_NUMERIC=C              LC_TIME=en_US.utf8        LC_COLLATE=en_US.utf8    
 [5] LC_MONETARY=en_US.utf8    LC_MESSAGES=en_US.utf8    LC_PAPER=en_US.utf8       LC_NAME=C                
 [9] LC_ADDRESS=C              LC_TELEPHONE=C            LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C      

time zone: Asia/Shanghai
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.3.1
> 
chainsawriot commented 1 year ago

Thank you very much! The most immediate thing that I can do is to use rhub's Fedora instance to check the package.

https://builder.r-hub.io/status/original/readODS_2.1.1.tar.gz-5a4bad741cdb412a94c50f4f86e2c5e1

And it returned okay.

I was wondering whether it is a general issue in your Fedora setup with compiling packages using cpp11 (by looking at the output). Could you please try installing another package that uses cpp11; let's say haven or readxl? Probably readxl would be more relevant.

xning commented 1 year ago

It's ok to install readxl:

> install.packages("readxl", dependencies = T)
Installing package into ‘/home/xibo/R/x86_64-redhat-linux-gnu-library/4.3’
(as ‘lib’ is unspecified)
trying URL 'https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/contrib/readxl_1.4.3.tar.gz'
Content type 'application/octet-stream' length 2093488 bytes (2.0 MB)
==================================================
downloaded 2.0 MB

* installing *source* package ‘readxl’ ...
** package ‘readxl’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
using C compiler: ‘gcc (GCC) 13.2.1 20230728 (Red Hat 13.2.1-1)’
using C++ compiler: ‘g++ (GCC) 13.2.1 20230728 (Red Hat 13.2.1-1)’
g++ -std=gnu++17 -I"/usr/include/R" -DNDEBUG -Iunix -I. -I'/usr/share/R/library/cpp11/include' -I'/home/xibo/R/x86_64-redhat-linux-gnu-library/4.3/progress/include' -I/usr/local/include   -fvisibility=hidden -fpic  -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer   -c cpp11.cpp -o cpp11.o
g++ -std=gnu++17 -I"/usr/include/R" -DNDEBUG -Iunix -I. -I'/usr/share/R/library/cpp11/include' -I'/home/xibo/R/x86_64-redhat-linux-gnu-library/4.3/progress/include' -I/usr/local/include   -fvisibility=hidden -fpic  -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer   -c XlsWorkBook.cpp -o XlsWorkBook.o
g++ -std=gnu++17 -I"/usr/include/R" -DNDEBUG -Iunix -I. -I'/usr/share/R/library/cpp11/include' -I'/home/xibo/R/x86_64-redhat-linux-gnu-library/4.3/progress/include' -I/usr/local/include   -fvisibility=hidden -fpic  -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer   -c XlsxWorkBook.cpp -o XlsxWorkBook.o
g++ -std=gnu++17 -I"/usr/include/R" -DNDEBUG -Iunix -I. -I'/usr/share/R/library/cpp11/include' -I'/home/xibo/R/x86_64-redhat-linux-gnu-library/4.3/progress/include' -I/usr/local/include   -fvisibility=hidden -fpic  -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer   -c zip.cpp -o zip.o
g++ -std=gnu++17 -I"/usr/include/R" -DNDEBUG -Iunix -I. -I'/usr/share/R/library/cpp11/include' -I'/home/xibo/R/x86_64-redhat-linux-gnu-library/4.3/progress/include' -I/usr/local/include   -fvisibility=hidden -fpic  -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer   -c Read.cpp -o Read.o
gcc -I"/usr/include/R" -DNDEBUG -Iunix -I. -I'/usr/share/R/library/cpp11/include' -I'/home/xibo/R/x86_64-redhat-linux-gnu-library/4.3/progress/include' -I/usr/local/include   -fvisibility=hidden -fpic  -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer   -c cran.c -o cran.o
gcc -I"/usr/include/R" -DNDEBUG -Iunix -I. -I'/usr/share/R/library/cpp11/include' -I'/home/xibo/R/x86_64-redhat-linux-gnu-library/4.3/progress/include' -I/usr/local/include   -fvisibility=hidden -fpic  -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer   -c libxls/xlstool.c -o libxls/xlstool.o
gcc -I"/usr/include/R" -DNDEBUG -Iunix -I. -I'/usr/share/R/library/cpp11/include' -I'/home/xibo/R/x86_64-redhat-linux-gnu-library/4.3/progress/include' -I/usr/local/include   -fvisibility=hidden -fpic  -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer   -c libxls/endian.c -o libxls/endian.o
gcc -I"/usr/include/R" -DNDEBUG -Iunix -I. -I'/usr/share/R/library/cpp11/include' -I'/home/xibo/R/x86_64-redhat-linux-gnu-library/4.3/progress/include' -I/usr/local/include   -fvisibility=hidden -fpic  -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer   -c libxls/ole.c -o libxls/ole.o
gcc -I"/usr/include/R" -DNDEBUG -Iunix -I. -I'/usr/share/R/library/cpp11/include' -I'/home/xibo/R/x86_64-redhat-linux-gnu-library/4.3/progress/include' -I/usr/local/include   -fvisibility=hidden -fpic  -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer   -c libxls/xls.c -o libxls/xls.o
gcc -I"/usr/include/R" -DNDEBUG -Iunix -I. -I'/usr/share/R/library/cpp11/include' -I'/home/xibo/R/x86_64-redhat-linux-gnu-library/4.3/progress/include' -I/usr/local/include   -fvisibility=hidden -fpic  -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer   -c libxls/locale.c -o libxls/locale.o
g++ -std=gnu++17 -shared -L/usr/lib64/R/lib -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -o readxl.so cpp11.o XlsWorkBook.o XlsxWorkBook.o zip.o Read.o cran.o libxls/xlstool.o libxls/endian.o libxls/ole.o libxls/xls.o libxls/locale.o -L/usr/lib64/R/lib -lR
installing to /home/xibo/R/x86_64-redhat-linux-gnu-library/4.3/00LOCK-readxl/00new/readxl/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
  converting help for package ‘readxl’
    finding HTML links ... done
    cell-specification                      html  
    finding level-2 HTML links ... done

    excel_format                            html  
    excel_sheets                            html  
    read_excel                              html  
    readxl-package                          html  
    readxl_example                          html  
    readxl_progress                         html  
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (readxl)

The downloaded source packages are in
    ‘/tmp/RtmpUodOb4/downloaded_packages’
> 
chainsawriot commented 1 year ago

Thank you very much again.

I have tried this locally (But i must admit that I am no expert in Fedora).

docker run --rm -it fedora

And then inside the container

dnf install R -y ; Rscript -e "install.packages('readODS', repo = 'https://mirrors.tuna.tsinghua.edu.cn/CRAN/')"

readODS was compiled fine.

> require(readODS)
Loading required package: readODS
> sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Fedora Linux 38 (Container Image)

Matrix products: default
BLAS/LAPACK: FlexiBLAS OPENBLAS-OPENMP;  LAPACK version 3.11.0

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
 [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
 [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
[10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

time zone: Etc/UTC
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] readODS_2.1.0

loaded via a namespace (and not attached):
[1] compiler_4.3.1
> 

Of course, no computational environment is 100% the same. And I don't know how different is your current computational environment to the one bootstrapped by Docker. So, it probably won't help.

Could you please also try the following and report:

  1. install.packages("readODS", repos = "https://ropensci.r-universe.dev")
  2. remotes::install_github('ropensci/readODS')

If both still do not work, I think there are some precautionary steps I can take to "prevent" this, e.g.

https://github.com/ropensci/readODS/blob/7548c3ab8778efc2d6058fc56ca84920b2e3a92f/src/write_sheet_file_.cpp#L157-L159

To

    for (int i = 0; i < sheet_names.size(); i++) {
        cpp11::data_frame current_df;
        write_df(current_df, sheet_names[i], row_names, col_names, na_as_string, padding, xml_file);
    }

But this problem should have been fixed since a decade.