如何使用 R 4.1 中的 Octave?

Posted

技术标签:

【中文标题】如何使用 R 4.1 中的 Octave?【英文标题】:How can I use Octave from R 4.1? 【发布时间】:2021-11-30 20:38:04 【问题描述】:

我已经使用以下代码在 Linux 机器(Ubuntu 20.04)中安装了 Octave:

sudo apt-add-repository -y ppa:octave/stable; 
sudo apt install -y software-properties-common; 
sudo apt-get update; 
sudo apt-get install -y octave liboctave-dev

该程序使用他的界面完美运行。

我现在想通过 RcppOctave 库通过 R 使用它,但我什至无法安装它。

由于R版本,使用默认安装不起作用:

> install.packages('RcppOctave')
Installing package into ‘/home/cesarkero/R/x86_64-pc-linux-gnu-library/4.1’
(as ‘lib’ is unspecified)
Warning in install.packages :
  package ‘RcppOctave’ is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
> install.packages("RcppOctave", repos="http://R-Forge.R-project.org")
Installing package into ‘/home/cesarkero/R/x86_64-pc-linux-gnu-library/4.1’
(as ‘lib’ is unspecified)
Warning in install.packages :
  package ‘RcppOctave’ is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages

然后我尝试从 github (install_github('https://github.com/renozao/RcppOctave')) 或直接从 tar.gz 最新版本安装它,但这是我得到的错误:

> file <- '../../05_Software/R/RcppOctave_0.8.5.tar.gz'
> install.packages(pkgs=file, type="source", repos=NULL)
Installing package into ‘/home/cesarkero/R/x86_64-pc-linux-gnu-library/4.1’
(as ‘lib’ is unspecified)
* installing *source* package ‘RcppOctave’ ...
** package ‘RcppOctave’ successfully unpacked and MD5 sums checked
** using staged installation
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking whether R is a shared library... yes
Using R LDFLAGS: -Wl,--export-dynamic -fopenmp -Wl,-Bsymbolic-functions -Wl,-z,relro -L/usr/lib/R/lib -lR -lpcre2-8 -llzma -lbz2 -lz -lrt -ldl -lm -licuuc -licui18n
Using R CPPFLAGS: -I/usr/share/R/include
checking for octave-config... /usr/bin/octave-config
checking for mkoctfile... /usr/bin/mkoctfile
checking Octave include directory... /usr/include/octave-5.2.0/octave
checking Octave library directory... /usr/lib/x86_64-linux-gnu/octave/5.2.0
checking Octave version... 5.2.0
checking whether to infer output names for Octave function (>= 3.4.3)... yes
configure: creating ./config.status
config.status: creating src/Makevars
configure: creating ./config.status
config.status: creating src/Makevars
config.status: creating src/modules/Makefile
** libs
cd modules;\
make; \
mkdir -p "/home/cesarkero/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-RcppOctave/00new/RcppOctave/modules"; \
echo "Moving Octave modules to '"/home/cesarkero/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-RcppOctave/00new/RcppOctave/modules"'"; \
cp -f PKG_ADD *.oct "/home/cesarkero/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-RcppOctave/00new/RcppOctave/modules";
make[1]: se entra en el directorio '/tmp/RtmpJjatgt/R.INSTALL144cc3d8bf8b1/RcppOctave/src/modules'
/usr/bin/mkoctfile -v -c -I/usr/share/R/include  Rrng.cc 
g++ -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-5.2.0/octave/.. -I/usr/include/octave-5.2.0/octave  -pthread -fopenmp -g -O2 -fdebug-prefix-map=/build/octave-rvRilm/octave-5.2.0=. -fstack-protector-strong -Wformat -Werror=format-security   -I/usr/share/R/include  Rrng.cc -o Rrng.o
Rrng.cc:32:10: fatal error: octave/config.h: No existe el archivo o el directorio
   32 | #include <octave/config.h>
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.
make[1]: *** [Makefile:25: Rrng.oct] Error 1
make[1]: se sale del directorio '/tmp/RtmpJjatgt/R.INSTALL144cc3d8bf8b1/RcppOctave/src/modules'
Moving Octave modules to '/home/cesarkero/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-RcppOctave/00new/RcppOctave/modules'
cp: no se puede efectuar `stat' sobre '*.oct': No existe el archivo o el directorio
make: *** [Makevars:18: OctaveModule] Error 1
ERROR: compilation failed for package ‘RcppOctave’
* removing ‘/home/cesarkero/R/x86_64-pc-linux-gnu-library/4.1/RcppOctave’
Warning in install.packages :
  installation of package ‘../../05_Software/R/RcppOctave_0.8.5.tar.gz’ had non-zero exit status

目标很明确:如何在 R 4.1(Ubuntu 机器 20.04)中安装这个库?


更新(21 年 10 月 20 日)

我已将此命令用作@Gorka sujested:

sudo ln -s /usr/include/octave-5.2.0/octave/octave-config.h /usr/include/octave-5.2.0/octave/config.h

...但这是新错误:

> install_github('https://github.com/renozao/RcppOctave')
Downloading GitHub repo renozao/RcppOctave@HEAD
✓  checking for file ‘/tmp/Rtmp2OpHDN/remotes23297a629ef/renozao-RcppOctave-fcf4d02/DESCRIPTION’ ...
─  preparing ‘RcppOctave’:
✓  checking DESCRIPTION meta-information ...
─  cleaning src
─  running ‘cleanup’
─  installing the package to process help pages
         -----------------------------------
─  installing *source* package ‘RcppOctave’ ...
   ** using staged installation
   checking R architecture... none
   checking for R... /usr/lib/R/bin/R
   checking for Rscript... /usr/lib/R/bin/Rscript
   checking whether loading Rprofile writes to stdout... no
   checking R version... R version 4.1.1 (2021-08-10)
   checking R platform... x86_64-pc-linux-gnu
   checking R CC... gcc -std=gnu99
   checking R CFLAGS... -g -O2 -fdebug-prefix-map=/build/r-base-QwogzP/r-base-4.1.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -Wall -pedantic -fdiagnostics-color=always
   checking R CPPFLAGS... 
   checking R CXXFLAGS... -g -O2 -fdebug-prefix-map=/build/r-base-QwogzP/r-base-4.1.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -Wall -pedantic -fdiagnostics-color=always
   checking for gcc... /usr/bin/gcc
   checking for gcc... gcc -std=gnu99
   checking whether the C compiler works... yes
   checking for C compiler default output file name... a.out
   checking for suffix of executables... 
   checking whether we are cross compiling... no
   checking for suffix of object files... o
   checking whether we are using the GNU C compiler... yes
   checking whether gcc -std=gnu99 accepts -g... yes
   checking for gcc -std=gnu99 option to accept ISO C89... none needed
   checking for g++... g++
   checking whether we are using the GNU C++ compiler... yes
   checking whether g++ accepts -g... yes
   checking for g++... /usr/bin/g++
   configure: Original R_LDFLAGS: -Wl,--export-dynamic -fopenmp -Wl,-Bsymbolic-functions -Wl,-z,relro -L/usr/lib/R/lib -lR -lpcre2-8 -llzma -lbz2 -lz -lrt -ldl -lm -licuuc -licui18n
   configure: Original R_CPPFLAGS: -I/usr/share/R/include
   checking whether R is a shared library... yes
   checking type of Operating System... Linux
   checking whether OS is Mac OS (Darwin)... no
   configure: Using mkoctfile with R_LDFLAGS: -Wl,--export-dynamic  -Wl,-Bsymbolic-functions -Wl,-z,relro -L/usr/lib/R/lib -lR -lpcre2-8 -llzma -lbz2 -lz -lrt -ldl -lm -licuuc -licui18n
   configure: Using mkoctfile with R_CPPFLAGS: -I/usr/share/R/include
   checking Octave custom binary path specification... none
   configure: using Octave binary path from $PATH
   checking for octave-config... /usr/bin/octave-config
   checking for mkoctfile... /usr/bin/mkoctfile
   checking Octave Octave bin directory... /usr/bin
   checking Octave Octave libraries directory... /usr/lib/x86_64-linux-gnu/octave/5.2.0
   checking for octave... /usr/bin/octave
   checking PATH changes... none
   checking Octave module make target... all
   checking mkoctfile command... /usr/bin/mkoctfile
   checking Octave cpp flags... -Wdate-time -D_FORTIFY_SOURCE=2
   checking Octave include flags... -I/usr/include/octave-5.2.0/octave/.. -I/usr/include/octave-5.2.0/octave
   checking Octave -L flags... warning: LFLAGS is deprecated and will be removed in a future version of Octave, use LDFLAGS instead
    -L/usr/lib/x86_64-linux-gnu
   checking Octave libraries... -loctinterp -loctave 
   checking Octave C compiler... gcc
   checking Octave Fortran compiler... gfortran
   checking Octave platform... x86_64-pc-linux-gnu
   checking Octave API version... api-v53
   checking Octave version... 5.2.0
   checking whether to infer output names for Octave function (>= 3.4.3)... yes
   configure: Using Octave LDFLAGS:   -L/usr/lib/x86_64-linux-gnu -loctinterp -loctave 
   configure: Using Octave CPPFLAGS: -Wdate-time -D_FORTIFY_SOURCE=2 -I/usr/include/octave-5.2.0/octave/.. -I/usr/include/octave-5.2.0/octave -DOCT_POST_3_4_0=1
   checking RcppOctave Octave module directory... /tmp/Rtmprp7Rn4/Rinst241a34c4f6ea/00LOCK-RcppOctave/00new/RcppOctave/modules
   configure: creating ./config.status
   config.status: creating R/config-vars.R
   configure: creating ./config.status
   config.status: creating R/config-vars.R
   config.status: creating src/Makevars
   configure: creating ./config.status
   config.status: creating R/config-vars.R
   config.status: creating src/Makevars
   config.status: creating src/modules/Makefile
   ** libs
   # Making Octave module [r_arch: all]
   make[1]: se entra en el directorio '/tmp/Rtmprp7Rn4/Rbuild241a5f538b08/RcppOctave/src/modules'
   *** Building octave module: utils.oct
   /usr/bin/mkoctfile -v utils.cc
   g++ -std=gnu++11 -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-5.2.0/octave/.. -I/usr/include/octave-5.2.0/octave  -pthread -fopenmp -g -O2 -fdebug-prefix-map=/build/octave-rvRilm/octave-5.2.0=. -fstack-protector-strong -Wformat -Werror=format-security    utils.cc -o /tmp/oct-XxPJKC.o
   g++ -I/usr/include/octave-5.2.0/octave/.. -I/usr/include/octave-5.2.0/octave  -pthread -fopenmp -g -O2 -fdebug-prefix-map=/build/octave-rvRilm/octave-5.2.0=. -fstack-protector-strong -Wformat -Werror=format-security -shared -Wl,-Bsymbolic -Wl,-Bsymbolic-functions -Wl,-z,relro  -o utils.oct  /tmp/oct-XxPJKC.o    -L/usr/lib/x86_64-linux-gnu  -Wl,-Bsymbolic-functions -Wl,-z,relro 
   *** Building octave module: Rrng.oct
   /usr/bin/mkoctfile -v -I/usr/share/R/include -Wl,--export-dynamic  -Wl,-Bsymbolic-functions -Wl,-z,relro -L/usr/lib/R/lib -lR -lpcre2-8 -llzma -lbz2 -lz -lrt -ldl -lm -licuuc -licui18n Rrng.cc
   g++ -std=gnu++11 -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-5.2.0/octave/.. -I/usr/include/octave-5.2.0/octave  -pthread -fopenmp -g -O2 -fdebug-prefix-map=/build/octave-rvRilm/octave-5.2.0=. -fstack-protector-strong -Wformat -Werror=format-security   -I/usr/share/R/include  Rrng.cc -o /tmp/oct-zr4Boo.o
   Rrng.cc: In function ‘octave_value_list Frand(const octave_value_list&, int)’:
   Rrng.cc:163:54: warning: ‘bool octave_value::is_empty() const’ is deprecated: [4.4]: use 'isempty' instead [-Wdeprecated-declarations]
     163 |   k = ( nargs > iarg_col && !args(iarg_col).is_empty() ? long(args(iarg_col).double_value()) : n);\
         |                                                      ^
   Rrng.cc:181:1: note: in expansion of macro ‘RAND_ARGS’
     181 | RAND_ARGS(octave_fun, 0, 2, 0, 1) \
         | ^~~~~~~~~
   Rrng.cc:196:3: note: in expansion of macro ‘RAND_FUNCTION’
     196 |   RAND_FUNCTION(unif_rand, "rand")
         |   ^~~~~~~~~~~~~
   In file included from /usr/include/octave-5.2.0/octave/../octave/ovl.h:36,
                    from /usr/include/octave-5.2.0/octave/../octave/ov-fcn.h:33,
                    from /usr/include/octave-5.2.0/octave/../octave/ov-builtin.h:32,
                    from /usr/include/octave-5.2.0/octave/../octave/defun-int.h:30,
                    from /usr/include/octave-5.2.0/octave/../octave/defun-dld.h:32,
                    from /usr/include/octave-5.2.0/octave/../octave/oct.h:32,
                    from Rrng.cc:33:
   /usr/include/octave-5.2.0/octave/../octave/ov.h:534:8: note: declared here
     534 |   bool is_empty (void) const
         |        ^~~~~~~~
   Rrng.cc: In function ‘octave_value_list Frandn(const octave_value_list&, int)’:
   Rrng.cc:163:54: warning: ‘bool octave_value::is_empty() const’ is deprecated: [4.4]: use 'isempty' instead [-Wdeprecated-declarations]
     163 |   k = ( nargs > iarg_col && !args(iarg_col).is_empty() ? long(args(iarg_col).double_value()) : n);\
         |                                                      ^
   Rrng.cc:181:1: note: in expansion of macro ‘RAND_ARGS’
     181 | RAND_ARGS(octave_fun, 0, 2, 0, 1) \
         | ^~~~~~~~~
   Rrng.cc:207:2: note: in expansion of macro ‘RAND_FUNCTION’
     207 |  RAND_FUNCTION(norm_rand, "randn")
         |  ^~~~~~~~~~~~~
   In file included from /usr/include/octave-5.2.0/octave/../octave/ovl.h:36,
                    from /usr/include/octave-5.2.0/octave/../octave/ov-fcn.h:33,
                    from /usr/include/octave-5.2.0/octave/../octave/ov-builtin.h:32,
                    from /usr/include/octave-5.2.0/octave/../octave/defun-int.h:30,
                    from /usr/include/octave-5.2.0/octave/../octave/defun-dld.h:32,
                    from /usr/include/octave-5.2.0/octave/../octave/oct.h:32,
                    from Rrng.cc:33:
   /usr/include/octave-5.2.0/octave/../octave/ov.h:534:8: note: declared here
     534 |   bool is_empty (void) const
         |        ^~~~~~~~
   Rrng.cc: In function ‘octave_value_list Frande(const octave_value_list&, int)’:
   Rrng.cc:163:54: warning: ‘bool octave_value::is_empty() const’ is deprecated: [4.4]: use 'isempty' instead [-Wdeprecated-declarations]
     163 |   k = ( nargs > iarg_col && !args(iarg_col).is_empty() ? long(args(iarg_col).double_value()) : n);\
         |                                                      ^
   Rrng.cc:181:1: note: in expansion of macro ‘RAND_ARGS’
     181 | RAND_ARGS(octave_fun, 0, 2, 0, 1) \
         | ^~~~~~~~~
   Rrng.cc:218:2: note: in expansion of macro ‘RAND_FUNCTION’
     218 |  RAND_FUNCTION(exp_rand, "rande")
         |  ^~~~~~~~~~~~~
   In file included from /usr/include/octave-5.2.0/octave/../octave/ovl.h:36,
                    from /usr/include/octave-5.2.0/octave/../octave/ov-fcn.h:33,
                    from /usr/include/octave-5.2.0/octave/../octave/ov-builtin.h:32,
                    from /usr/include/octave-5.2.0/octave/../octave/defun-int.h:30,
                    from /usr/include/octave-5.2.0/octave/../octave/defun-dld.h:32,
                    from /usr/include/octave-5.2.0/octave/../octave/oct.h:32,
                    from Rrng.cc:33:
   /usr/include/octave-5.2.0/octave/../octave/ov.h:534:8: note: declared here
     534 |   bool is_empty (void) const
         |        ^~~~~~~~
   Rrng.cc: In function ‘octave_value_list Frandg(const octave_value_list&, int)’:
   Rrng.cc:163:54: warning: ‘bool octave_value::is_empty() const’ is deprecated: [4.4]: use 'isempty' instead [-Wdeprecated-declarations]
     163 |   k = ( nargs > iarg_col && !args(iarg_col).is_empty() ? long(args(iarg_col).double_value()) : n);\
         |                                                      ^
   Rrng.cc:232:3: note: in expansion of macro ‘RAND_ARGS’
     232 |   RAND_ARGS("randg", 1, 4, 1, 2)
         |   ^~~~~~~~~
   In file included from /usr/include/octave-5.2.0/octave/../octave/ovl.h:36,
                    from /usr/include/octave-5.2.0/octave/../octave/ov-fcn.h:33,
                    from /usr/include/octave-5.2.0/octave/../octave/ov-builtin.h:32,
                    from /usr/include/octave-5.2.0/octave/../octave/defun-int.h:30,
                    from /usr/include/octave-5.2.0/octave/../octave/defun-dld.h:32,
                    from /usr/include/octave-5.2.0/octave/../octave/oct.h:32,
                    from Rrng.cc:33:
   /usr/include/octave-5.2.0/octave/../octave/ov.h:534:8: note: declared here
     534 |   bool is_empty (void) const
         |        ^~~~~~~~
   Rrng.cc:238:48: warning: ‘bool octave_value::is_empty() const’ is deprecated: [4.4]: use 'isempty' instead [-Wdeprecated-declarations]
     238 |   double scale(nArgs >= 4 && !args(3).is_empty() ? args(3).double_value() : 1);
         |                                                ^
   In file included from /usr/include/octave-5.2.0/octave/../octave/ovl.h:36,
                    from /usr/include/octave-5.2.0/octave/../octave/ov-fcn.h:33,
                    from /usr/include/octave-5.2.0/octave/../octave/ov-builtin.h:32,
                    from /usr/include/octave-5.2.0/octave/../octave/defun-int.h:30,
                    from /usr/include/octave-5.2.0/octave/../octave/defun-dld.h:32,
                    from /usr/include/octave-5.2.0/octave/../octave/oct.h:32,
                    from Rrng.cc:33:
   /usr/include/octave-5.2.0/octave/../octave/ov.h:534:8: note: declared here
     534 |   bool is_empty (void) const
         |        ^~~~~~~~
   Rrng.cc: In function ‘octave_value_list Frandp(const octave_value_list&, int)’:
   Rrng.cc:163:54: warning: ‘bool octave_value::is_empty() const’ is deprecated: [4.4]: use 'isempty' instead [-Wdeprecated-declarations]
     163 |   k = ( nargs > iarg_col && !args(iarg_col).is_empty() ? long(args(iarg_col).double_value()) : n);\
         |                                                      ^
   Rrng.cc:256:3: note: in expansion of macro ‘RAND_ARGS’
     256 |   RAND_ARGS("randp", 2, 3, 1, 2)
         |   ^~~~~~~~~
   In file included from /usr/include/octave-5.2.0/octave/../octave/ovl.h:36,
                    from /usr/include/octave-5.2.0/octave/../octave/ov-fcn.h:33,
                    from /usr/include/octave-5.2.0/octave/../octave/ov-builtin.h:32,
                    from /usr/include/octave-5.2.0/octave/../octave/defun-int.h:30,
                    from /usr/include/octave-5.2.0/octave/../octave/defun-dld.h:32,
                    from /usr/include/octave-5.2.0/octave/../octave/oct.h:32,
                    from Rrng.cc:33:
   /usr/include/octave-5.2.0/octave/../octave/ov.h:534:8: note: declared here
     534 |   bool is_empty (void) const
         |        ^~~~~~~~
   g++ -I/usr/include/octave-5.2.0/octave/.. -I/usr/include/octave-5.2.0/octave  -pthread -fopenmp -g -O2 -fdebug-prefix-map=/build/octave-rvRilm/octave-5.2.0=. -fstack-protector-strong -Wformat -Werror=format-security -shared -Wl,-Bsymbolic -Wl,-Bsymbolic-functions -Wl,-z,relro  -o Rrng.oct  /tmp/oct-zr4Boo.o   -Wl,--export-dynamic -Wl,-Bsymbolic-functions -Wl,-z,relro -L/usr/lib/R/lib -lR -lpcre2-8 -llzma -lbz2 -lz -lrt -ldl -lm -licuuc -licui18n  -L/usr/lib/x86_64-linux-gnu  -Wl,-Bsymbolic-functions -Wl,-z,relro 
   make[1]: se sale del directorio '/tmp/Rtmprp7Rn4/Rbuild241a5f538b08/RcppOctave/src/modules'
   # Copying Octave modules to directory '/tmp/Rtmprp7Rn4/Rinst241a34c4f6ea/00LOCK-RcppOctave/00new/RcppOctave/modules'
   g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG `"/usr/lib/R/bin/Rscript" -e "Rcpp:::CxxFlags()"` -Wdate-time -D_FORTIFY_SOURCE=2 -I/usr/include/octave-5.2.0/octave/.. -I/usr/include/octave-5.2.0/octave -DOCT_POST_3_4_0=1  -I'/home/cesarkero/R/x86_64-pc-linux-gnu-library/4.1/Rcpp/include'    -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-QwogzP/r-base-4.1.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -Wall -pedantic -fdiagnostics-color=always -c conversion.cpp -o conversion.o
   In file included from /usr/include/octave-5.2.0/octave/../octave/lo-utils.h:35
                    from /usr/include/octave-5.2.0/octave/../octave/Array.h:41
                    from /usr/include/octave-5.2.0/octave/../octave/str-vec.h:32
                    from /usr/include/octave-5.2.0/octave/../octave/ovl.h:33
                    from rcpp_octave.h:32
                    from conversion.cpp:5
   /usr/include/octave-5.2.0/octave/../octave/quit.h:178:2:warning: tra ‘;-Wpedantic
     178 | ;
         |  ^
   In file included from /usr/include/octave-5.2.0/octave/../octave/boolMatrix.h:30
                    from /usr/include/octave-5.2.0/octave/../octave/mx-base.h:34
                    from /usr/include/octave-5.2.0/octave/../octave/ov.h:40
                    from /usr/include/octave-5.2.0/octave/../octave/ovl.h:36
                    from rcpp_octave.h:32
                    from conversion.cpp:5
   /usr/include/octave-5.2.0/octave/../octave/boolNDArray.h:121:46:warning: tra ‘;-Wpedantic
     121 | BSXFUN_OP_DECL (and, boolNDArray, OCTAVE_API);
         |                                              ^
   /usr/include/octave-5.2.0/octave/../octave/boolNDArray.h:122:45:warning: tra ‘;-Wpedantic
     122 | BSXFUN_OP_DECL (or, boolNDArray, OCTAVE_API);
         |                                             ^
   conversion.cpp:n function ‘SEXPREC* wrap(const Cell&, bool)
   conversion.cpp:134:9:error: const class Cellhas no member named ‘is_cellstr did you mean ‘iscellstr
     134 |  if(  x.is_cellstr
         |         ^~~~~~~~~~
         |         iscellstr
   conversion.cpp:n function ‘SEXPREC* Rcpp::wrap(const T&) [with T = octave_value; SEXP = SEXPREC*]
   conversion.cpp:180:24:warning: bool octave_value::is_null_value() constdeprecated: [4.4]: use 'isnull' instead [-Wdeprecated-declarations
     180 |  if( val.is_null_value()
         |                        ^
   In file included from /usr/include/octave-5.2.0/octave/../octave/ovl.h:36
                    from rcpp_octave.h:32
                    from conversion.cpp:5
   /usr/include/octave-5.2.0/octave/../octave/ov.h:633:8:note: red here
     633 |   bool is_null_valued) const
         |        ^~~~~~~~~~~~~
   conversion.cpp:214:30:warning: bool octave_value::is_bool_type() constdeprecated: [4.4]: use 'islogical' instead [-Wdeprecated-declarations
     214 |   else if ( val.is_bool_type()
         |                              ^
   In file included from /usr/include/octave-5.2.0/octave/../octave/ovl.h:36
                    from rcpp_octave.h:32
                    from conversion.cpp:5
   /usr/include/octave-5.2.0/octave/../octave/ov.h:701:8:note: red here
     701 |   bool is_bool_typed) const
         |        ^~~~~~~~~~~~
   conversion.cpp:219:102:warning: bool octave_value::is_integer_type() constdeprecated: [4.4]: use 'isinteger' instead [-Wdeprecated-declarations
     219 |   else if( val.is_int32_type() || val.is_int64_type() || val.is_int16_type() || val.is_integer_type()
         |                                                                                                      ^
   In file included from /usr/include/octave-5.2.0/octave/../octave/ovl.h:36
                    from rcpp_octave.h:32
                    from conversion.cpp:5
   /usr/include/octave-5.2.0/octave/../octave/ov.h:692:8:note: red here
     692 |   bool is_integer_typed) const
         |        ^~~~~~~~~~~~~~~
   conversion.cpp:223:30:warning: bool octave_value::is_real_type() constdeprecated: [4.4]: use 'isreal' instead [-Wdeprecated-declarations
     223 |   else if( val.is_real_type()
         |                              ^
   In file included from /usr/include/octave-5.2.0/octave/../octave/ovl.h:36
                    from rcpp_octave.h:32
                    from conversion.cpp:5
   /usr/include/octave-5.2.0/octave/../octave/ov.h:708:8:note: red here
     708 |   bool is_real_typed) const
         |        ^~~~~~~~~~~~
   conversion.cpp:250:33:warning: bool octave_value::is_integer_type() constdeprecated: [4.4]: use 'isinteger' instead [-Wdeprecated-declarations
     250 |   else if ( val.is_integer_type()
         |                                 ^
   In file included from /usr/include/octave-5.2.0/octave/../octave/ovl.h:36
                    from rcpp_octave.h:32
                    from conversion.cpp:5
   /usr/include/octave-5.2.0/octave/../octave/ov.h:692:8:note: red here
     692 |   bool is_integer_typed) const
         |        ^~~~~~~~~~~~~~~
   conversion.cpp:255:30:warning: bool octave_value::is_real_type() constdeprecated: [4.4]: use 'isreal' instead [-Wdeprecated-declarations
     255 |   else if( val.is_real_type()
         |                              ^
   In file included from /usr/include/octave-5.2.0/octave/../octave/ovl.h:36
                    from rcpp_octave.h:32
                    from conversion.cpp:5
   /usr/include/octave-5.2.0/octave/../octave/ov.h:708:8:note: red here
     708 |   bool is_real_typed) const
         |        ^~~~~~~~~~~~
   conversion.cpp:270:24:warning: bool octave_value::is_map() constdeprecated: [4.4]: use 'isstruct' instead [-Wdeprecated-declarations
     270 |   else if( val.is_map()/ Maps are converted into lists
         |                        ^
   In file included from /usr/include/octave-5.2.0/octave/../octave/ovl.h:36
                    from rcpp_octave.h:32
                    from conversion.cpp:5
   /usr/include/octave-5.2.0/octave/../octave/ov.h:594:8:note: red here
     594 |   bool is_mapd) const
         |        ^~~~~~
   conversion.cpp:307:25:warning: bool octave_value::is_cell() constdeprecated: [4.4]: use 'iscell' instead [-Wdeprecated-declarations
     307 |   else if( val.is_cell() Cell objects are used for character vectors
         |                         ^
   In file included from /usr/include/octave-5.2.0/octave/../octave/ovl.h:36
                    from rcpp_octave.h:32
                    from conversion.cpp:5
   /usr/include/octave-5.2.0/octave/../octave/ov.h:541:8:note: red here
     541 |   bool is_celld) const
         |        ^~~~~~~
   conversion.cpp:n function ‘T Rcpp::as(SEXP) [with T = octave_value; SEXP = SEXPREC*]
   conversion.cpp:471:50:error: valid initialization of reference of type ‘const octave_value&from expression of type ‘octave_value_list
     471 |    const octave_value& ol = as<octave_value_list>(x)
         |                             ~~~~~~~~~~~~~~~~~~~~~^~~
   make: *** [/usr/lib/R/etc/Makeconf:177: conversion.o] Error 1
   ERROR: compilation failed for package ‘RcppOctave’
─  removing ‘/tmp/Rtmprp7Rn4/Rinst241a34c4f6ea/RcppOctave’
         -----------------------------------
   ERROR: package installation failed
Error: Failed to install 'RcppOctave' from GitHub:
  System command 'R' failed, exit status: 1, stdout + stderr (last 10 lines):
E>       |        ^~~~~~~
E> conversion.cpp:n function ‘T Rcpp::as(SEXP) [with T = octave_value; SEXP = SEXPREC*]
E> conversion.cpp:471:50:error: valid initialization of reference of type ‘const octave_value&from expression of type ‘octave_value_list
E>   471 |    const octave_value& ol = as<octave_value_list>(x)
E>       |                             ~~~~~~~~~~~~~~~~~~~~~^~~
E> make: *** [/usr/lib/R/etc/Makeconf:177: conversion.o] Error 1
E> ERROR: compilation failed for package ‘RcppOctave’
E> * removing ‘/tmp/Rtmprp7Rn4/Rinst241a34c4f6ea/RcppOctave’
E>       -----------------------------------
E> ERROR: package installation failed

【问题讨论】:

这个包是off CRAN since 2017,所以你认为它“只是构建”的假设可能是无效的。您是否尝试通过 GitHub 存储库的问题单联系作者? 似乎在新版本的octave中,文件octave/config.h已经被octave/octave-config.h替换了。 sudo ln -s /usr/include/octave-5.2.0/octave/octave-config.h /usr/include/octave-5.2.0/octave/config.h 是否解决了构建问题? 谢谢。看来从github安装更进一步,但出现了一个新的错误。 查看swig_octave_version.h 文件。我认为您需要为 RcppOctave 使用 Octave 版本 3.8 或更低版本。 假设最新版本的包在上传时确实有效,我会下载这个版本的源代码(cran.r-project.org/src/contrib/Archive/RcppOctave/…)。该版本于 2015 年 10 月 6 日发布。所以我会下载并安装当天最新的 Octave 版本(甚至可能有点旧 - 请参阅wiki.octave.org/Release_History) - 所以尝试安装版本 4.0.0 或 3.8.2 【参考方案1】:

我也未能在 R 4.1.2 中安装 RcppOctave

相反,我找到了一种在 R Markdown file 中运行 Octave 脚本的方法。看看这个例子:

```octave, engine.path='/usr/local/opt/octave/bin/octave', warning=F
addpath('/Applications/freesurfer/matlab')

[vertex_coords_sp, faces] = read_surf("/Applications/freesurfer/subjects/fsaverage5/surf/lh.sphere")

save('~/RAS_coord_fs_sphere.mat','-v6')
```

您可以参考this page 了解更多关于 R Markdown 中 Octave 代码的详细信息。

希望这可以帮助那些在处理拆分环境时也遇到困难的人:D

【讨论】:

嗨@joão-dias 感谢您的编辑。我宁愿保留反引号,因为这就是 RStudio GUI 和 other posts here 中代码的样子,这可能对 R Markdown 的新手更友好。 好的,明白了。我以为是错字;)【参考方案2】:

有时,当出现package ... is not available for this version of R 错误消息时,您自己下载和安装/构建软件包就足够了。

在这种情况下显然不是......当 Gorka 说它可能是 Octave 版本时,他可能是对的。

一般来说,我宁愿尝试运行最新的 CRAN 版本 RcppOctave_0.18.1 而不是 GitHub 版本(其最新更新也是几年前的)。

由于该软件包似乎是临时或永久停产,因此您永远不知道他们是否在一些无效的更改中停止了他们的 Github 版本。

而对于最新的 CRAN 版本,它更有可能是一个主打版本,在它被上传的时候可以工作 (2015-10-06)。

因此,如果您从此时复制环境(R 版本、包依赖项版本、Ubuntu 版本、Octave 版本),您很有可能让这个包运行。

但在RcppOctave_0.18.1 发布时将 Octave 版本引入当前版本也可能已经完成了这项工作。 查看https://wiki.octave.org/Release_History 表明版本4.0.03.8.2 可能很合适。

我不是真正的 linux/ubuntu 用户,但我猜只是

apt-get install octave=4.0.0

不会安装包,因为包必须存在于存储库/包管理器中。可能你必须从某个地方获取旧的包版本/添加一个包含包版本的存储库(你也在你的代码中使用apt-add-repository -y ppa ...)。

对于 Ubuntu,您可以在启动板找到旧软件包 https://launchpad.net/ubuntu/trusty/+source/octave https://launchpad.net/ubuntu/+source/octave/3.8.2-4.1

对于 Debian,您可以在以下位置找到旧软件包 https://snapshot.debian.org/

看看构建包是否适用于 Octave 4.0.03.8.2(以及是否可以安装它们)会很有趣。

如果你让它以这种方式运行,并且无论如何你不需要更新 Octave 版本的功能 - 完美。

如果不是...我不知道任何其他 R - Octave 接口包,这可能会排除仅使用另一个 R 包的解决方案。

一种解决方案(取决于您的计划)可能是使用 system() / system2() 来调用系统命令。

系统调用command指定的操作系统命令。

因为(据我所知)您还可以从 shell 运行 Octave 脚本,这可能是一种可能的解决方法。

【讨论】:

感谢您的回答,但我宁愿不使用旧版本的 octave。即使我对此一无所知,我也需要一门课程,并且可能最终会发现其他问题,例如功能更改,或者其他。无论如何,我会尝试安装旧版本,然后检查 R 是否可以使用它。 根据您想要做什么,您可以尝试通过 shell 使用 Octave 脚本(您可以通过 R 的 system() 使用 - 请参见答案的底部)。因此,这些脚本仍然可以以某种方式成为 R 工作流程的一部分/由 R 触发。您必须阅读脚本的输出。根据您希望如何与 Octave 代码交互,这将意味着额外的努力。

以上是关于如何使用 R 4.1 中的 Octave?的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Octave 中读取 hdf 数据

Octave,如何保存绘图图?

如何将Octave连接到Oracle数据库?

如何在 C/C++ 程序中嵌入 GNU Octave?

如何在mac上配置Octave以获取上一个命令

如何使用 Fink 在 Mac 上安装 GNU Octave?