LyX: Undefined control sequence \hline - lyx

Running LyX on Windows 7 with MiKTeX. I was trying to export LyX's "Embedded Objects tutorial" to PDF, but got this error:
Undefined control sequence
\hline
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
The offending code seems to be
\let\myHlineC\hline
\renewcommand{\hline}
{\arrayrulecolor{red}\myHlineC\arrayrulecolor{black}}
(section 2.11.2 of the document).
May or may not be relevant: The document's preamble.

You can download the pdf of the manual online here:
http://wiki.lyx.org/LyX/DocumentationDevelopment#EmbeddedObjects
Do you have the following packages installed?
arydshln, colortbl, diagbox, lettrine, marginnote, picinpar and sidecap
Although it says that you should be able to export without them, I've found that sometimes they are required. If this is true in your case, can you post which package was causing the problem so we can try to fix the document? To find this out, install the above packages one by one and test if you can export after each one. Don't forget to reconfigure LyX via Tools > Reconfigure after each install of a new package.

Related

Trying to render R4DS to pdf

When I try to render the latest version of the book R for Data Science (R4DS), I get as far as LaTeX compilation, then am stopped by the following error message.
! Text line contains an invalid character.
l.406 #> -- ^^[
[1mAttaching packages^^[[22m --------------------------------...
Error: LaTeX failed to compile _main.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See _main.log for more info.
>
This corresponds to the part of the R4DS book where we are shown how to load the tidyverse and, looking at the _main.tex file, I see many lines with what look like ANSI escape sequences starting on this line. They have the form ^[[1m, ^[[22m, and so on. I manually compiled the LaTeX output using lualatex and found that there are dozens if not hundreds of examples of this throughout the book. I suspected it was because I was using the colorout package in R, but it appears that that package is required, so others who are rendering successfully must be using it too. I believe I have successfully updated all relevant packages.
It looks like I "solved" the problem by changing an option in the _common.R file from crayon.enabled=TRUE to crayon.enabled=FALSE. This removed the ANSI escape sequences from the book. Previously I had tried setting options(crayon.enabled=FALSE) in my R session, but this was evidently being overridden by the setting in _common.R.
Update: 23 Nov 2022
The process for rendering the files is completely different now because of the switch to Quarto. Here's how I did it.
Rscript -e 'update.packages()'
Rscript -e 'install.packages('quarto')'
Rscript -e 'devtools::install_github("hadley/r4ds")
git clone https://github.com/hadley/r4ds.git
cd r4ds
Next, I wrote a small perl script to avoid the error messages I was getting about trying to render html material to pdf. (I'm omitting a lot of dead-ends I encountered in the process.)
#!/usr/bin/perl
use File::Slurp qw(prepend_file);
my #files = glob( '*.qmd' );
my $header = "\n---\nprefer-html: true\n---\n\n";
foreach my $file (#files) {
prepend_file($file, $header);
}
I ran the above script in the r4ds directory.
Next I loaded R and did the following:
library(quarto)
quarto_render("index.qmd", output_format = "pdf")
The above failed with the error message: "\begin{document} not found". Luckily, the aborted process leaves an index.tex file I can process and also gives a line number for the error. I went to that line number in the index.tex file and deleted the block of html I found there.
After that, I ran
lualatex index.tex
twice and got a successful render, minus the cover page. (You could presumably run xelatex index.tex instead.) There are a lot of problems with my render, such as the plots being too large to fit on the page. If I decide to spend time fixing them (unlikely, since Hadley seems to want us to use the online version) I'll modify this answer.

R Hide internal objects in package from autocomplete

I am developing a package in Rstudio and I am trying to save object as internal to the package so that the user cannot see it. I make a default package project in Rstudio called "testpackage" and then execute:
library(devtools)
test.hidden.object <- 1:5
use_data(test.hidden.object,internal = T,overwrite = T)
Then I build the package, which saves it to my library. Then I restart Rstudio, and execute:
library(testpackage)
test.hidden.object
It prints out: [1] 1 2 3 4 5
The environment is empty, executing:
ls()
prints out "character(0)"
From what I understand, it is not possible to hide an object in a package from the user if the user knows the name of object, and I don't want to do that. But what worries me is that the autocomplete functionally is able to find these objects.
In both Rstudio and the R console, if I load the package and then type "test.hid" and then press TAB I can see the object "test.hidden.object" as an option. Should autocomplete be able to reveal internal objects? Am I building the package incorrectly?
To fix this problem I have so far updated R, Rstudio, devtools, and I have manually created the sysdata.rda file myself instead of using "use_data", but each time I am able to see the internal objects with autocomplete.
I think you are mistaken in your description. Autocompletion in RStudio and other R front ends will only show symbols that are visible in the current context. Your users can't make use of symbols that aren't exported, so autocompletion won't display them.
You may see hidden symbols while editing files in your own package, because your package code can see hidden symbols. But your users won't.
Edited to add: I've just followed your instructions more closely, and managed to duplicate what you saw. The problem is that by default the NAMESPACE file declares everything to be public, regardless of the setting for internal. This looks like a devtools misunderstanding or bug.
To fix it, manually edit your NAMESPACE file to make sure only public symbols are exported.
2nd edit: The docs for devtools::use_data have been updated on Github. They now say "If TRUE, stores all objects in a single R/sysdata.rda file. Objects in this file follow the usual export rules. Note that this means they will be exported if you are using the common exportPattern()
rule which exports all objects except for those that start with .."

How to solve this error message in rmarkdown?

I am just starting to explore the rmarkdown package. I don't use Rstudio. I use the default R environment. What I did was as follows.
I created a new R document.
Started typing few lines in rmarkdown format.
Saved the file with Rmd extension.
I saved the file in the working directory.
I installed the pandoc using the pkg file.
I installed 'rmarkdown' package. Loaded the package.
Used the following command to render the Rmd file.
rmarkdown::render("Untitled.Rmd")
I get the following error.
Error in tools::file_path_as_absolute(input) : file 'Untitled.Rmd'
does not exist
I tried all the possible ways such as giving the exact path instead of filename etc. But nothing worked out. I googled the error message and found that none had similar error. Can someone help me with this. What I am missing. What the error message mean?
Most of the time the error file not found is either a type error or a real missing file (as in your case, the real one is named in another way).
In order to discard those possibilities:
Copy the fullpath from your filebrowser.
Make sure the file exists, inside R you could type:
file.exists("/fullpath/to/file")
If that return TRUE and the error persists, then you suspect another thing is going on.

GNAT Programming Suite: Cross-Reference Info Not Up To Date (this is a guess)

I'm trying to get package references resolved during a build, using GNAT Programming Suite (hosted on Win XP). In the Builder Results, I get errors like this one:
file "ac_configuration_s.ada" not found
Clicking on the error takes me to a line like this:
with
Ac_Configuration,
Dispense_Timer,
...
The first item (Ac_Configuration) isn't resolved, but the second item (Dispense_Time) is resolved. I have several others that do or don't resolve. All of the files in question (spec and body) are identified as source files.
When I hover my mouse over the line with the error, a popup shows up that offers this:
(Cross-references info not up to date. This is a guess.)
Ac_Configuration
local package declared at D_Ac_Config_S.Ada:85
The guess is correct, but I don't know how to use this. How do I get this to correctly build?
Update
Here is teh call to gcc
gcc -c "-gnatec=C:\Source\build\GNAT-TEMP-000001.TMP" -I- -gnatA
-x ada "-gnatem=C:\Source\build\GNAT-TEMP-000002.TMP" "C:\Source\C_Cbt_Main_B.Ada"
I don't see a reference to teh "miimal" switch.
In this case, there is no corresponding body file file D_Ac_Config_S.Ada. So the is no body file to compile separately.
When I right click on the package reference inside the with, I can goto the declaration of Ac_Configuration and every other package name that is the source of an error. So these lreferences are being resolved somehow.
By the way, I have not used ADA before, so I'm still trying to understand everything.
It looks as though you're using _s.ada as the suffix for specs, and I'm guessing _b.ada for bodies?
GNAT may have difficulty with this naming convention. It's possible, using a GNAT Project file (.gpr), to alter GNAT's default convention ({unit-name}.ads for specs, {unit-name}.adb for bodies) but the rules (see "Spec_Suffix") say "It cannot start with an underscore followed by an alphanumeric character" (I haven't tried this, but you can see that it would confuse the issue if you had a package Foo_S, for example).
LATER: It turns out that GNAT (GPL, 4.7, 4.8) is quite happy with your suffixes!
If the package Ac_Configuration is really a local package declared at line 85 of D_Ac_Config_S.Ada, then there's your problem; you can only with a library unit, which in this case would be D_Ac_Config.
with D_Ac_Config;
...
package Foo is
...
Bar : D_Ac_Config.Ac_Configuration.Baz;
I wonder whether D_Ac_Config_S.Ada (for example) actually contains multiple Ada units? (if so, compiling that file should result in a compilation error such as end of file expected, file can have only one compilation unit). GNAT doesn't support this at compile time, providing instead a utility gnatchop.
Would it be possible to just gnatchop all the source and be done with it?
Hm, I think it sounds like the compiler's got a bad set of objects/ALIs it's working with, hence the cross-reference not up to date error. (Usually the compiler's good about keeping things up to date; but you may want to check to see if the "minimal recompilation" switch is set for the project.)
Have you tried compiling just the ["owning"] file D_Ac_Config_S.Ada? (i.e. if it were a spec, go to the corresponding body and compile that.) That should force its ALI/object files to be updated.
Then try building as normal.
-- PS: you might have to clean first.

How do I access any NOTEs that might appear while checking a package?

While running R CMD check, one can receive an Error, a Warning, or a NOTE. I'd like to check if a NOTE was generated and if so access the contents of the NOTE programmatically.
My goal is to see if a NOTE was generated that indicates the submission does not yet exist on CRAN. I know there are other ways to check that, but it seems a shame to reinvent the wheel since devtools::check() already generates a message if that is the case.
Well, R is open source, and this comes from the file src/library/tools/R/build.R. So why not start there?
edd#max:~/src/debian/R/R-2.15.1/src/library/tools/R$ grep '"NOTE' build.R
resultLog(Log, "NOTE")
sprintf("NOTE: There were %d notes.\n",
sprintf("NOTE: There was 1 note.\n"))
edd#max:~/src/debian/R/R-2.15.1/src/library/tools/R$

Resources