How to build a package with RcppArmadillo? - r

I wish to build a package, but I write part of it using RcppArmadillo and now I am suffering the consequences. I am using roxygen2 and devtools to help me with DESCRIPTION and NAMESPACE. I am coding in R / Ubuntu. In the DESCRIPTION I include two lines to load the packages:
Depends: R (>= 3.4.4), MASS (>= 7.3-49), Rcpp (>= 1.0.5), RcppArmadillo (>= 0.9.900.2.0)
LinkingTo: Rcpp, RcppArmadillo
and in the folder /src I write a script name loss_function.cpp, inside it there is:
> // [[Rcpp::depends(RcppArmadillo)]]
>
> #include <RcppArmadillo.h>
>
> using namespace Rcpp;
>
> //' Check function.
> //'
> //' #param x vector
> //' #param tau percentile
> //' #return y new vector
> // [[Rcpp::export(rho_koenker)]]
> arma::vec rho_koenker(arma::vec x, double tau){
> int n = x.n_elem;
> arma::vec y(n);
> for(int i = 0; i < n; ++i){
> if(x(i)<0){
> y(i) = x(i)*(tau-1);
> } else {
> y(i) = x(i)*tau;
> }
> }
> return(y);
> }
>
> //' Quantile regression loss function
> //'
> //' #param beta parameter
> //' #param x matrix
> //' #param y vector
> //' #param tau percentile
> //' #param N total number of observations
> //' #param d beta's length
> //' #return eta numeric
> // [[Rcpp::export(loss_qr)]]
> double loss_qr(arma::vec beta, arma::mat x, arma::vec y, double tau, int N, int d){
> double eta = 0;
> arma::vec res(N);
> arma::vec rho(N);
> res = y - (x * beta);
> rho = rho_koenker(res,tau);
> eta = accu(rho);
> return(eta);
> }
When I check the package (build -> check package) there comes an error msg:
Error in .Call("_pqfe_loss_qr", PACKAGE = "pqfe", beta, x, y, tau, N, :
"_pqfe_loss_qr" not available for .Call() for package "pqfe"
Calls: qr ... optim_qr -> <Anonymous> -> <Anonymous> -> fn -> .Call
Execution halted
Warning message:
Can't find generic `sew` in package knitr to register S3 method.
This message is only shown to developers using devtools.
Do you need to update knitr to the latest version?

As alluded in the comment above, it is not clear where you error would lie here with RcppArmadillo. So I
invoked RcppArmadillo.package.skeleton() (via the helper command kitten.r from littler relying on pkgKitten but those are details)
added in src/loss_function.cpp based on what you had
added one missing #export tag to you doxygen/roxygen to also have the R documentation created
called Rcpp::compileAttributes() (via helper compAttr.r from `littler) to have the interal glue code generated / updated
called roxygenize() (via helper roxy.r from littler) to have help files created
called R CMD build (directly, or via helper build.r from littler)
ran R CMD check (directly, or via helper rcc.r from littler)
and it all works:
edd#rob:~/git/stackoverflow/73405262(master)$ R CMD build soDemo
* checking for file ‘soDemo/DESCRIPTION’ ... OK
* preparing ‘soDemo’:
* checking DESCRIPTION meta-information ... OK
* cleaning src
* installing the package to process help pages
* saving partial Rd database
* cleaning src
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building ‘soDemo_1.0.tar.gz’
edd#rob:~/git/stackoverflow/73405262(master)$
and checks nicely too
edd#rob:~/git/stackoverflow/73405262(master)$ R CMD check soDemo_1.0.tar.gz
* using log directory ‘/home/edd/git/stackoverflow/73405262/soDemo.Rcheck’
* using R version 4.2.1 (2022-06-23)
* using platform: x86_64-pc-linux-gnu (64-bit)
* using session charset: UTF-8
* checking for file ‘soDemo/DESCRIPTION’ ... OK
* checking extension type ... Package
* this is package ‘soDemo’ version ‘1.0’
* package encoding: UTF-8
* checking package namespace information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking if there is a namespace ... OK
* checking for executable files ... OK
* checking for hidden files and directories ... OK
* checking for portable file names ... OK
* checking for sufficient/correct file permissions ... OK
* checking whether package ‘soDemo’ can be installed ... OK
* checking installed package size ... OK
* checking package directory ... OK
* checking DESCRIPTION meta-information ... OK
* checking top-level files ... OK
* checking for left-over files ... OK
* checking index information ... OK
* checking package subdirectories ... OK
* checking R files for non-ASCII characters ... OK
* checking R files for syntax errors ... OK
* checking whether the package can be loaded ... OK
* checking whether the package can be loaded with stated dependencies ... OK
* checking whether the package can be unloaded cleanly ... OK
* checking whether the namespace can be loaded with stated dependencies ... OK
* checking whether the namespace can be unloaded cleanly ... OK
* checking loading without being on the library search path ... OK
* checking dependencies in R code ... OK
* checking S3 generic/method consistency ... OK
* checking replacement functions ... OK
* checking foreign function calls ... OK
* checking R code for possible problems ... OK
* checking Rd files ... OK
* checking Rd metadata ... OK
* checking Rd cross-references ... OK
* checking for missing documentation entries ... OK
* checking for code/documentation mismatches ... OK
* checking Rd \usage sections ... OK
* checking Rd contents ... OK
* checking for unstated dependencies in examples ... OK
* checking line endings in C/C++/Fortran sources/headers ... OK
* checking line endings in Makefiles ... OK
* checking compilation flags in Makevars ... OK
* checking for GNU extensions in Makefiles ... OK
* checking for portable use of $(BLAS_LIBS) and $(LAPACK_LIBS) ... OK
* checking use of PKG_*FLAGS in Makefiles ... OK
* checking compilation flags used ... OK
* checking compiled code ... OK
* checking examples ... OK
* checking for unstated dependencies in ‘tests’ ... OK
* checking tests ...
Running ‘tinytest.R’
OK
* checking PDF version of manual ... OK
* DONE
Status: OK
edd#rob:~/git/stackoverflow/73405262(master)$
I put the tarball here if you want to take it from there.

Related

R Install and Restart fails

I have been working on an R package for work for sometime and have been making updates and installing it to my machine for over a year. For some reason, last month, I can no longer build to source, binary and hence I cannot install and restart.
When I choose the document option:
==> devtools::document(roclets = c('rd', 'collate', 'namespace'))
i Updating LICHospitalR documentation
i Loading LICHospitalR
Writing NAMESPACE
Writing NAMESPACE
Documentation completed
It runs successfully.
Now when I click Install and Restart
==> Rcmd.exe INSTALL --no-multiarch --with-keep.source LICHospitalR
* installing to library 'C:/Users/bha485/Documents/R/win-library/4.1'
* installing *binary* package 'LICHospitalR' ...
cp: unknown option -- )
Try '/usr/bin/cp --help' for more information.
ERROR: installing binary package failed
* removing 'C:/Users/bha485/Documents/R/win-library/4.1/LICHospitalR'
* restoring previous 'C:/Users/bha485/Documents/R/win-library/4.1/LICHospitalR'
Exited with status 1.
Also when I do a check:
==> devtools::check()
i Updating LICHospitalR documentation
i Loading LICHospitalR
Registered S3 method overwritten by 'tune':
method from
required_pkgs.model_spec parsnip
Registered S3 methods overwritten by 'stars':
method from
st_bbox.SpatRaster sf
st_crs.SpatRaster sf
Writing NAMESPACE
Writing NAMESPACE
-- Building ------------------------------------- LICHospitalR --
Setting env vars:
* CFLAGS : -Wall -pedantic -fdiagnostics-color=always
* CXXFLAGS : -Wall -pedantic -fdiagnostics-color=always
* CXX11FLAGS: -Wall -pedantic -fdiagnostics-color=always
-----------------------------------------------------------------
v checking for file 'C:\Users\bha485\Desktop\LICHospitalR/DESCRIPTION' ...
- preparing 'LICHospitalR': (3.3s)
v checking DESCRIPTION meta-information ...
v checking whether 'INDEX' is up-to-date (929ms)
- installing the package to build vignettes
-----------------------------------
- installing *binary* package 'LICHospitalR' ...
cp: unknown option -- )
Try '/usr/bin/cp --help' for more information.
ERROR: installing binary package failed
- removing 'C:/Users/bha485/AppData/Local/Temp/RtmpQX3Cq3/Rinst1e246e7f3ee6/LICHospitalR'
-----------------------------------
ERROR: package installation failed
Error: System command 'Rcmd.exe' failed, exit status: 1, stdout + stderr:
E> * checking for file 'C:\Users\bha485\Desktop\LICHospitalR/DESCRIPTION' ... OK
E> * preparing 'LICHospitalR':
E> * checking DESCRIPTION meta-information ... OK
E> * checking whether 'INDEX' is up-to-date ... OK
E> * installing the package to build vignettes
E> -----------------------------------
E> * installing *binary* package 'LICHospitalR' ...
E> cp: unknown option -- )
E> Try '/usr/bin/cp --help' for more information.
E> ERROR: installing binary package failed
E> * removing 'C:/Users/bha485/AppData/Local/Temp/RtmpQX3Cq3/Rinst1e246e7f3ee6/LICHospitalR'
E> -----------------------------------
E> ERROR: package installation failed
Stack trace:
1. devtools::check(, check_dir = dirname(getwd()))
2. withr::with_envvar(pkgbuild::compiler_flags(FALSE), action = "pre ...
3. base:::force(code)
4. pkgbuild::build(pkg$path, tempdir(), args = build_args, quiet = q ...
5. withr::with_temp_libpaths(rcmd_build_tools(options$cmd, c(options ...
6. base:::force(code)
7. pkgbuild:::rcmd_build_tools(options$cmd, c(options$path, options$ ...
8. pkgbuild:::with_build_tools(callr::rcmd_safe(..., env = env, ...
9. withr::with_path(rtools_path(), code)
10. base:::force(code)
11. callr::rcmd_safe(..., env = env, spinner = FALSE, show = FALSE, ...
12. callr:::run_r(options)
13. base:::with(options, with_envvar(env, do.call(processx::run, ...
14. base:::with.default(options, with_envvar(env, do.call(processx::r ...
15. base:::eval(substitute(expr), data, enclos = parent.frame())
16. base:::eval(substitute(expr), data, enclos = parent.frame())
17. callr:::with_envvar(env, do.call(processx::run, c(list(bin, args ...
18. base:::force(code)
19. base:::do.call(processx::run, c(list(bin, args = real_cmdargs, ...
20. (function (command = NULL, args = character(), error_on_status = TRUE, ...
21. throw(new_process_error(res, call = sys.call(), echo = echo, ...
x System command 'Rcmd.exe' failed, exit status: 1, stdout + stderr:
E> * checking for file 'C:\Users\bha485\Desktop\LICHospitalR/DESCRIPTION' ... OK
E> * preparing 'LICHospitalR':
E> * checking DESCRIPTION meta-information ... OK
E> * checking whether 'INDEX' is up-to-date ... OK
E> * installing the package to build vignettes
E> -----------------------------------
E> * installing *binary* package 'LICHospitalR' ...
E> cp: unknown option -- )
E> Try '/usr/bin/cp --help' for more information.
E> ERROR: installing binary package failed
E> * removing 'C:/Users/bha485/AppData/Local/Temp/RtmpQX3Cq3/Rinst1e246e7f3ee6/LICHospitalR'
E> -----------------------------------
E> ERROR: package installation failed
Execution halted
Exited with status 1.
Session Info:
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.1.0 tools_4.1.0
>
I really do not know where to go from here, should I file this as an issue on the github rstudio/rstudio? Or is there another avenue I can take.
UPDATE
GitHub of Project

Jupyter download as pdf

How can I solve this problem when I want to download as pdf through Jupyter?
nbconvert failed: PDF creating failed, captured latex output:
Failed to run "['xelatex', './notebook.tex', '-quiet']" command:
This is XeTeX, Version 3.14159265-2.6-0.999991 (TeX Live 2019) (preloaded format=xelatex)
restricted \write18 enabled.
entering extended mode
(./notebook.tex
LaTeX2e <2018-12-01>
'''(/usr/local/texlive/2019/texmf-dist/tex/latex/base/article.cls
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/size11.clo))
(/usr/local/texlive/2019/texmf-dist/tex/latex/tcolorbox/tcolorbox.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/pgf/basiclayer/pgf.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/pgf/utilities/pgfrcs.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/utilities/pgfutil-common.te
x
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/utilities/pgfutil-common-li
sts.tex))
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/utilities/pgfutil-latex.def
(/usr/local/texlive/2019/texmf-dist/tex/latex/ms/everyshi.sty))
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/utilities/pgfrcs.code.tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/pgf.revision.tex)))
(/usr/local/texlive/2019/texmf-dist/tex/latex/pgf/basiclayer/pgfcore.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics-def/xetex.def)))
(/usr/local/texlive/2019/texmf-dist/tex/latex/pgf/systemlayer/pgfsys.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/systemlayer/pgfsys.code.tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/utilities/pgfkeysfiltered.c
ode.tex))
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/systemlayer/pgf.cfg)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-xetex.de
f
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-dvipdfmx
.def
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-common-p
df.def))))
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/systemlayer/pgfsyssoftpath.
code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/systemlayer/pgfsysprotocol.
code.tex)) (/usr/local/texlive/2019/texmf-dist/tex/latex/xcolor/xcolor.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics-cfg/color.cfg))
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcore.code.tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathcalc.code.tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathutil.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathparser.code.tex
)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.code.
tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.basic
.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.trigo
nometric.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.rando
m.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.compa
rison.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.base.
code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.round
.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.misc.
code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.integ
erarithmetics.code.tex)))
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex)
)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepoints.co
de.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathconst
ruct.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathusage
.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorescopes.co
de.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcoregraphicst
ate.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcoretransform
ations.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorequick.cod
e.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreobjects.c
ode.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathproce
ssing.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorearrows.co
de.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreshade.cod
e.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreimage.cod
e.tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreexternal.
code.tex))
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorelayers.co
de.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcoretranspare
ncy.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepatterns.
code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorerdf.code.
tex)))
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/modules/pgfmoduleshapes.cod
e.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/modules/pgfmoduleplot.code.
tex)
(/usr/local/texlive/2019/texmf-dist/tex/latex/pgf/compatibility/pgfcomp-version
-0-65.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/pgf/compatibility/pgfcomp-version
-1-18.sty)) (/usr/local/texlive/2019/texmf-dist/tex/latex/tools/verbatim.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/environ/environ.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/trimspaces/trimspaces.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/tcolorbox/tcbbreakable.code.tex
Library (tcolorbox): 'tcbbreakable.code.tex' version '4.20'
)) (/usr/local/texlive/2019/texmf-dist/tex/latex/parskip/parskip.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)
(/usr/local/texlive/2019/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/local/texlive/2019/texmf-dist/tex/generic/oberdiek/etexcmds.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/oberdiek/ifluatex.sty)))))
(/usr/local/texlive/2019/texmf-dist/tex/generic/iftex/iftex.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/fontspec/fontspec.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/l3packages/xparse/xparse.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/l3kernel/expl3-code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/latex/l3kernel/l3xdvipdfmx.def)))
(/usr/local/texlive/2019/texmf-dist/tex/latex/fontspec/fontspec-xetex.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/fontenc.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/tuenc.def))
(/usr/local/texlive/2019/texmf-dist/tex/latex/fontspec/fontspec.cfg)))
(/usr/local/texlive/2019/texmf-dist/tex/latex/caption/caption.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/caption/caption3.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/adjustbox/adjustbox.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/xkeyval/xkeyval.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/xkeyval/xkeyval.tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/xkeyval/xkvutils.tex)))
(/usr/local/texlive/2019/texmf-dist/tex/latex/adjustbox/adjcalc.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/adjustbox/trimclip.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/collectbox/collectbox.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/adjustbox/tc-xetex.def))
(/usr/local/texlive/2019/texmf-dist/tex/latex/ifoddpage/ifoddpage.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/varwidth/varwidth.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/float/float.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/tools/enumerate.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/geometry/geometry.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/oberdiek/ifpdf.sty)
(/usr/local/texlive/2019/texmf-dist/tex/generic/oberdiek/ifvtex.sty)
(/usr/local/texlive/2019/texmf-dist/tex/generic/ifxetex/ifxetex.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsfonts/amssymb.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsfonts/amsfonts.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/textcomp.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/ts1enc.def))
(/usr/local/texlive/2019/texmf-dist/tex/latex/upquote/upquote.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/eurosym/eurosym.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/ucs/ucs.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/ucs/data/uni-global.def))
(/usr/local/texlive/2019/texmf-dist/tex/latex/fancyvrb/fancyvrb.sty
Style option: `fancyvrb' v3.2a <2019/01/15> (tvz))
(/usr/local/texlive/2019/texmf-dist/tex/latex/oberdiek/grffile.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/hyperref/hyperref.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/oberdiek/hobsub-hyperref.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/oberdiek/hobsub-generic.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/oberdiek/auxhook.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/hyperref/pd1enc.def)
(/usr/local/texlive/2019/texmf-dist/tex/latex/latexconfig/hyperref.cfg)
(/usr/local/texlive/2019/texmf-dist/tex/latex/url/url.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/hyperref/hxetex.def
(/usr/local/texlive/2019/texmf-dist/tex/latex/hyperref/puenc.def)
(/usr/local/texlive/2019/texmf-dist/tex/generic/oberdiek/stringenc.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/titling/titling.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/tools/longtable.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/booktabs/booktabs.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/enumitem/enumitem.sty)
(/usr/local/texlive/2019/texmf-dist/tex/generic/ulem/ulem.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/jknapltx/mathrsfs.sty)
No file notebook.aux.
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/ts1cmr.fd)
ABD: EveryShipout initializing macros
(/usr/local/texlive/2019/texmf-dist/tex/latex/caption/ltcaption.sty)
*geometry* driver: auto-detecting
*geometry* detected driver: xetex
*geometry* verbose mode - [ preamble ] result:
* driver: xetex
* paper: <default>
* layout: <same size as paper>
* layoutoffset:(h,v)=(0.0pt,0.0pt)
* modes:
* h-part:(L,W,R)=(72.26999pt, 469.75502pt, 72.26999pt)
* v-part:(T,H,B)=(72.26999pt, 650.43001pt, 72.26999pt)
* \paperwidth=614.295pt
* \paperheight=794.96999pt
* \textwidth=469.75502pt
* \textheight=650.43001pt
* \oddsidemargin=0.0pt
* \evensidemargin=0.0pt
* \topmargin=-37.0pt
* \headheight=12.0pt
* \headsep=25.0pt
* \topskip=11.0pt
* \footskip=30.0pt
* \marginparwidth=59.0pt
* \marginparsep=10.0pt
* \columnsep=10.0pt
* \skip\footins=10.0pt plus 4.0pt minus 2.0pt
* \hoffset=0.0pt
* \voffset=0.0pt
* \mag=1000
* \#twocolumnfalse
* \#twosidefalse
* \#mparswitchfalse
* \#reversemarginfalse
* (1in=72.27pt=25.4mm, 1cm=28.453pt)
(/usr/local/texlive/2019/texmf-dist/tex/latex/ucs/ucsencs.def)
(/usr/local/texlive/2019/texmf-dist/tex/latex/hyperref/nameref.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/oberdiek/gettitlestring.sty))
Package hyperref Warning: Rerun to get /PageLabels entry.
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsfonts/umsb.fd)
(/usr/local/texlive/2019/texmf-dist/tex/latex/jknapltx/ursfs.fd)
LaTeX Warning: No \author given.
! LaTeX Error: Command \b already defined.
Or name \end... illegal, see p.192 of the manual.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.384 \newcommand{\b}{\mathbf{b}}
?
! Emergency stop.
...
l.384 \newcommand{\b}{\mathbf{b}}
No pages of output.
Transcript written on notebook.log.

How do you set MAILTO in crontab programmatically?

I am currently creating my crontab programmatically as follows:
echo "* * * * * run_some_job" | crontab -
Additionally, I want to programmatically set the MAILTO address, is that possible? That is, without the interactive editor crontab -e
crontab can take multi line input.
So, give two lines, for example this way:
> (echo "MAILTO=xxx#yyy.org"; echo "* * * * * run_some_job") | crontab -
> crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (- installed on Fri Jan 24 16:26:20 2020)
# (Cronie version 4.2)
MAILTO=xxx#yyy.org
* * * * * run_some_job
And programmatically (because of unix-tag, C example):
#include <stdio.h>
void main()
{
FILE* file = popen("/usr/bin/crontab -", "w");
if (file)
{
fprintf(file, "MAILTO=xxx#yyy.org\n");
fprintf(file, "10 11 * * * run_some_job\n");
pclose(file);
}
}
result:
> gcc main.c
> ./a.out
> crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (- installed on Fri Jan 24 16:35:03 2020)
# (Cronie version 4.2)
MAILTO=xxx#yyy.org
10 11 * * * run_some_job

RcppTN .cpp script works when sourced but not when compiled in library

I am trying to create a R package that uses random draws from a truncated normal in a .cpp script. I am using the rtn1 function from the pckage RcppTN. If I source the code, the function works fine. Once I build the package I get the error:
> library(testtruncnorm)
> testtruncnorm()
Error in testtruncnorm::testtruncnorm() :
function 'RcppTN_rtn1' not provided by package 'RcppTN'
Simplified .cpp code is here
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppTN.h>
// [[Rcpp::depends(RcppTN)]]
#include<armadillo>
using namespace Rcpp;
//' draw truncated normal
//'
//' testtruncnorm()
//' #return returns 2 draws from a truncated normal
// [[Rcpp::export]]
arma::vec testtruncnorm()
{
arma::vec result = arma::ones(2);
result[1] = RcppTN::rtn1(1, 1, 0,HUGE_VAL);
result[2] = RcppTN::rtn1(1, 1, 0,HUGE_VAL);
return result;
}
My NAMESPACE file is
useDynLib(testtruncnorm, .registration=TRUE)
importFrom(Rcpp, evalCpp)
exportPattern("^[[:alpha:]]+")
My DESCRIPTION file is
Package: testtruncnorm
Type: Package
Title: What the Package Does Using Title Case
Version: 1.0
Date: 2018-10-23
Author: Your Name
Maintainer: Your Name <your#email.com>
Description: More details about what the package does. See
<http://cran.r-project.org/doc/manuals/r-release/R-exts.html#The-
DESCRIPTION-file>
for details on how to write this part.
License: GPL (>= 2)
Imports: Rcpp (>= 0.12.19), RcppTN
LinkingTo: Rcpp, RcppArmadillo, RcppTN
I am using RStudio create "R Package with RcppArmadillo" to get started. RStudio version 1.1.456. R version 3.5.1. Windows 10.
You have to make sure that RcppTN gets attached. You can do this using
importFrom(RcppTN, rtn)
in NAMESPACE. In the documentation for RcppTN it says that one should add
Depends: RcppTN
which should have the same effect.

Building package with Rcpp, generated .h file missing header

I am currently building a package in RStudio that uses Rcpp. I have defined the following .cpp file, which works with Rcpp::sourceCpp.
// [[Rcpp::plugins(cpp11)]]
// [[Rcpp::interfaces(r, cpp)]]
#include <Rcpp.h>
#include <unordered_set>
using namespace Rcpp;
// [[Rcpp::export]]
std::unordered_set<int> traverse_cor(NumericMatrix x, float maxcor) {
std::unordered_set<int> elements;
int ncol = x.ncol();
for(int i = 0; i < ncol; i++) {
for(int j = 0; j < ncol; j++) {
if(i < j) {
if(x(i, j) > maxcor && x(i, j) < 1){
elements.insert(i + 1);
}
}
}
}
return elements;
}
I am following the directions from here and here. Next I call Rcpp::compileAttributes(). This produces the following files:
src/RcppExports.cpp
R/RcppExports.R
inst/include/mypackage.h
inst/include/mypackage_RcppExports.h
The generated mypackage_RcppExports.h file looks as follows:
// This file was generated by Rcpp::compileAttributes
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
#ifndef __gwassim_RcppExports_h__
#define __gwassim_RcppExports_h__
#include <Rcpp.h>
namespace gwassim {
using namespace Rcpp;
namespace {
void validateSignature(const char* sig) {
Rcpp::Function require = Rcpp::Environment::base_env()["require"];
require("gwassim", Rcpp::Named("quietly") = true);
typedef int(*Ptr_validate)(const char*);
static Ptr_validate p_validate = (Ptr_validate)
R_GetCCallable("gwassim", "gwassim_RcppExport_validate");
if (!p_validate(sig)) {
throw Rcpp::function_not_exported(
"C++ function with signature '" + std::string(sig) + "' not found in gwassim");
}
}
}
inline std::unordered_set<int> traverse_cor(NumericMatrix x, float maxcor) {
typedef SEXP(*Ptr_traverse_cor)(SEXP,SEXP);
static Ptr_traverse_cor p_traverse_cor = NULL;
if (p_traverse_cor == NULL) {
validateSignature("std::unordered_set<int>(*traverse_cor)(NumericMatrix,float)");
p_traverse_cor = (Ptr_traverse_cor)R_GetCCallable("gwassim", "gwassim_traverse_cor");
}
RObject __result;
{
RNGScope __rngScope;
__result = p_traverse_cor(Rcpp::wrap(x), Rcpp::wrap(maxcor));
}
if (__result.inherits("interrupted-error"))
throw Rcpp::internal::InterruptedException();
if (__result.inherits("try-error"))
throw Rcpp::exception(as<std::string>(__result).c_str());
return Rcpp::as<std::unordered_set<int> >(__result);
}
}
#endif // __gwassim_RcppExports_h__
After attempting to build and reload the package, I receive the following errors (1):
../inst/include/gwassim_RcppExports.h:27:12: error: 'unordered_set' in
namespace 'std' does not name a type
And (2)
RcppExports.cpp:12:1: error: 'unordered_set' in namespace 'std' does
not name a type
I have limited C++ experience, but my sense is that these errors occur due to #include <unordered_set> being omitted. How do I get these automatically generated files to have the correct headers?
My sessionInfo is the following:
Session info ----------------------------------------------------------------------
setting value
version R version 3.1.0 (2014-04-10)
system x86_64, mingw32
ui RStudio (0.99.235)
language (EN)
collate English_United States.1252
tz America/New_York
Packages --------------------------------------------------------------------------
package * version date source
devtools 1.7.0.9000 2015-02-11 Github (hadley/devtools#9415a8a)
digest * 0.6.4 2013-12-03 CRAN (R 3.1.0)
memoise * 0.2.1 2014-04-22 CRAN (R 3.1.0)
mvtnorm 1.0-2 2014-12-18 CRAN (R 3.1.2)
Rcpp 0.11.4 2015-01-24 CRAN (R 3.1.2)
roxygen2 * 4.1.0 2014-12-13 CRAN (R 3.1.2)
rstudioapi * 0.2 2014-12-31 CRAN (R 3.1.2)
stringr * 0.6.2 2012-12-06 CRAN (R 3.0.0)
And my version of g++ is 4.6.3, as included in the RTools package for Windows. I have enabled C++11 features with the following:
Sys.setenv("PKG_CXXFLAGS"="-std=c++0x").
That is a finicky one. I think you want Section 3.5.2 of the Rcpp Attributes vignette and this trick:
The Package.h file does nothing other than include the
Package_RcppExports.h header. This is done so that package
authors can replace the Package.h header with a custom one
and still be able to include the automatically generated exports
(details on doing this are provided in the next section).
In passing, I think I also convinced you to create a package rather than to rely just on sourceCpp() :)
Edit: Doh!! I overlooked the part that
std::unordered_set<int> traverse_cor(NumericMatrix x, float maxcor)
is probably not an automatically wrappable function. You may need to convert your set into a vector (or list or ...) to get one of the types that matches naturally into R.

Resources