RStudio "Install and Restart" not ignoring files in .Rbuildignore - r

My .Rbuildignore specifies these files:
^inst/extdata$
This is a directory that holds some .csv files I use.
When I build my package with the "Install and Restart" button, these folders are included in the built package as demonstrated by:
> list.files(system.file(package = 'myPackage'), recursive = T, full.names = T)
...
[6] "C:/Users/JohnDoe/R/win-library/4.0/myPackage/extdata/df.csv"
...
However, if I build my package with the command devtools::install(), the inst/extdata folder is correctly ignored in the build process. This leads me to believe the discrepancy lies in the "Install and Restart" button. Is there any way to map this button to the devtools::install() command?

.Rbuildignore is used by the R CMD build command. If you install directly from a directory without building a tarball, it's not used. This is true for base R CMD INSTALL as well as the RStudio emulations of it.
So what you should do is to put the files somewhere else that isn't handled by R CMD INSTALL, for example in directory ignoreMe instead of a directory whose name means "install me".
If you don't want to do that, then it is possible to attach arbitrary R commands to keys in RStudio, but that's a lot of work. See http://rstudio.github.io/rstudioaddins/ if you want the details.

Related

Setting .libPaths() For Running R Scripts From Command Line Using Rscript.exe

I am trying to run R scripts via BAT files on Windows Command Prompt.
The scripts require a few R packages such as data.table, tidyR, etc.
For operational reasons, all required R packages and dependencies (including data.table) are installed at C:\Users\username\Documents\R\R-3.5.1\library. I am not allowed to install RStudio in this environment.
When I try
"C:\Program Files\R\R-3.5.1\bin\x64\Rscript.exe" script.R, I get an error similar to
Error in library(data.table) : there is no package called 'data.table'
Execution halted
How can I set the .libPaths via Command Prompt to point to the correct location of the packages (i.e. to C:\Users\username\Documents\R\R-3.5.1\library)?
Thank you in advance.
Disclaimer: I'm unfamiliar with R.
From R: Search paths :
The library search path is initialized at startup from the environment
variable R_LIBS (which should be a colon-separated list of directories
at which R library trees are rooted) followed by those in environment
variable R_LIBS_USER. Only directories which exist at the time will be
included.
By default R_LIBS is unset, and R_LIBS_USER is set to directory
‘R/R.version$platform-library/x.y’ of the home directory (or
‘Library/R/x.y/library’ for CRAN macOS builds), for R x.y.z.
An environment variable can be created with set VARIABLE_NAME=YOUR_VALUE batch command.
So your batch file should probably be something like this:
cd /d "C:\INSERT_PATH_TO_DIRECTORY_CONTAINING_script.R"
set "R_LIBS=C:\Users\username\Documents\R\R-3.5.1\library"
"C:\Program Files\R\R-3.5.1\bin\x64\Rscript.exe" script.R
However for portability reasons (let's say a collegue asks for a copy of your script or your computer dies) I suggest putting the script, R library and batch file in a single directory, let's say C:\Users\username\Documents\R. The batch file C:\Users\username\Documents\R\script.bat becomes:
cd /d "%~dp0"
set "R_LIBS=%~dp0R-3.5.1\library"
"%PROGRAMFILES%\R\R-3.5.1\bin\x64\Rscript.exe" "%~dpn0.R"
%PROGRAMFILES% environment variable expands to full path of program files folder, %~dp0 parameter expands to full path of a directory that holds your batch file, and %~dpn0 is a batch-file full path without extension.
Notice that %~dp0R-3.5.1 is not a typo because %~dp0 includes trailing backslash.
This way you can copy C:\Users\username\Documents\R to D:\Users\SOMEOTHERNAME\Documents\R and the script will still run.
If you create another version of your script, just copy the batch file so that it has same filename as your script but .bat extension instead of .R and it should call the new script - this has proven to be very handy when debugging and distributing scripts.
Alternatively, if you would rather install libraries separately you may want to use %HOMEDRIVE%%HOMEPATH% which expands to C:\Users\username.
Extracting proper Documents folder path, as well as R installation path is possible but requires reading the registry and thus is a bit more complicated.

Treetagger koRpus package error

I am trying to use the Treetag function in the koRpus package.
The code I have used is
tagged.text <-treetag("C:/Rec_By_Others.txt",treetagger="manual",lang="en",TT.options=list(path="C:\\Program Files\\TreeTagger", preset="en"))
But I keep encountering with the following error.
Error in matrix(unlist(strsplit(tagged.text, "\t")), ncol = 3, byrow = TRUE, :
'data' must be of a vector type, was 'NULL'
What do I do ?
Your code seems correct to me, but I had the same error message. I could not find any solution for this problem until today. I finally found that I had a problem with the PERL installation, so I reinstalled a new version of PERL. Then, I checked if TreeTagger worked properly by applying the README TreeTagger instruction, that is:
Installation
Install a Perl interpreter (if you have not already installed one). You can download a Perl interpreter for Windows for free at http://www.activestate.com/activeperl/
Extract the zip file (if it was not extracted yet) and move the TreeTagger directory to the root directory of drive C:.
Download the parameter files for the languages you need, decompress them (e.g. using Winzip or 7zip) and move them to the subdirectory TreeTagger/lib. Rename the parameter files to -utf8.par Example: Rename french-par-linux-3.2-utf8.bin to french-utf8.par Non-UTF8 parameter files are not supported anymore.
Add the path C:\TreeTagger\bin to the PATH environment variable. The necessary steps differ from one Windows version to the other.
Open a command prompt window and type the command set PATH=C:\TreeTagger\bin;%PATH%
Go to the directory C:\TreeTagger cd c:\TreeTagger
Now you can test the tagger, e.g. by analyzing this file with the command tag-english INSTALL.txt If you install the TreeTagger in a different directory, you have to modify the first path in the batch files tag-*.bat using an editor such as Wordpad.
Note also that:
if you install the TreeTagger in a different directory, you have to
modify the first path in the batch files tag-.bat using an editor
such as Wordpad.
I hope this help.

How to install stringi from local file (ABSOLUTELY no Internet Access)

I am working on a remote server using RStudio. This server has no access to the Internet. I would like to install the package "stringi." I have looked at this stackoverflow article, but whenever I use the command
install.packages("stringi_0.5-5.tar.gz",
configure.vars="ICUDT_DIR=/my/directory/for/icudt.zip")
It simply tries to access the Internet, which it cannot do. Up until now I have been using Tools -> Install Packages -> Install from Packaged Archive File. However, due to this error, I can no longer use this method.
How can I install this package?
If you have no internet access on local machines, you can build a distributable source package that includes all the required
ICU data files (for off-line use) by omitting some relevant lines in
the .Rbuildignore file. The following command sequence should do the trick:
wget https://github.com/gagolews/stringi/archive/master.zip -O stringi.zip
unzip stringi.zip
sed -i '/\/icu..\/data/d' stringi-master/.Rbuildignore
R CMD build stringi-master
Assuming the most recent development version is 1.3.1,
a file named stringi_1.3.1.tar.gz is created in the current working directory.
The package can now be installed (the source bundle may be propagated via
scp etc.) by executing:
R CMD INSTALL stringi_1.3.1.tar.gz
or by calling install.packages("stringi_1.3.1.tar.gz", repos=NULL),
from within an R session.
For a Linux machine the easiest way is from my point of view:
Download the release you need from Rexamine in tar.gz format to your local pc. In opposition to the version on CRAN it already contains the icu55\data\ folder.
Move the archive to your target linux machine without internet access
run R CMD INSTALL stringi-1.0-1.tar.gz (in case of release 1.0-1)
You provided the wrong value of configure.vars.
It indicates that you have to give the directory's name, not a final file name.
Correct your code to the following:
install.packages("stringi_0.5-5.tar.gz",
configure.vars="ICUDT_DIR=/my/directory/for/")
Regards,
Sean
Follow the steps below
Download icudt55l.zip seperately from server where you have internet access with
wget http://www.mini.pw.edu.pl/~gagolews/stringi/icudt55l.zip
Copy the downloaded packages to the server where you want to install stringi
Execute the following command
R CMD INSTALL --configure-vars='ICUDT_DIR=/tmp/ALL' stringi_1.1.6.tar.gz
icudt55l.zip is copied to /tmp/ALL
The suggestion from #gagolews almost worked for me. Here's what actually did the trick with RStudio.
Download the master.zip file that will save as stringi-master.zip.
Unzip the file onto your desktop. The unzipped folder should be stringi-master.
Edit the .Rbuildignore file by removing ^src/icu55/data and ^src/icu61/data or similar lines.
Move the folder from your desktop to the home directory of your server.
Create a New Project in RStudio with ~/stringi-master as the Existing Directory
From RStudio's menu, select Build and Build Source Package. (You may need to first select Configure Build Tools. For Project build tools choose Package then select OK.)
It should create a tar.gz file, in the following format: stringi_x.x.(x+1).tar.gz. For example, if the current version of stringi is 1.5.3, it will create version 1.5.4. (I received a few warnings that didn't seem to affect the outcome.)
Move the newly created package to your local repository. Update the repository index. And install the package.

R CMD build leaves compiled .o files in src folder

I am one of the author of the R package xgboost. When I tried to pack it with R CMD build xgboost, there are 5 new compiled .o files inside src/.
I double checked that these files are not in the directory before. And strangely, this problem disappears when I run R CMD build --no-build-vignettes xgboost. I suspect there are something related to the process of compiling the vignettes. However we don't want to sacrifice the vignettes for it.
How can this be fixed? Thanks!
NOTE: To reproduce the problem, please run the following command in your console:
git clone https://github.com/tqchen/xgboost && cd xgboost && make Rpack
where make Rpack is a combination of file operations that move files to the correct places and R CMD operations. Edit the Rpack part in Makefile to control this flow.
OK after some attempts the following solution works for me:
Create a file named .Rbuildignore
Fill it with the file names (patterns) that you don't need.
An example is this file: https://github.com/dmlc/xgboost/blob/master/R-package/.Rbuildignore

How do I convert Rd files to pdf for a package that I am creating in R?

I am writing a package in R and I would appreciate some example bash code to process the Rd files to latex and then to pdf.
It is in the directory ~/mypkg/dev/. I have generated the file structure and Rd templates.
from ~/mypkg/dev/man, I have tried
R CMD Rdconv -o mypkg-package.tex --type=latex mypkg-package.Rd
mypkg-package.tex file is generated, but
pdflatex mypkg-package.tex
generates tex without any preamble.
I have read the documentation in "Writing R extensions" and "R CMD Rdconv --help" on this subject, but no examples are provided.
Thank you
There are two issues here:
First, the Rdconv command only transforms one Rd file at a time; your question suggests that you want the full manual.
Second, the Rd2dvi command is your friend. I just ran the following on a local package:
R CMD Rd2dvi --pdf --title='Test of foo' -o /tmp/foo.pdf man/*.Rd
That should be what you asked for.
Try this. It worked for me.
found from Making an R package PDF manual using devtools
pack <- "name_of_your_package"
path <- find.package(pack)
system(paste(shQuote(file.path(R.home("bin"), "R")),"CMD", "Rd2pdf", shQuote(path)))
0. From question, it is assumed that you have .Rd files.
You may have obtained these .Rd files via roxygen package or some other ways. You need .pdf of your package. One way to do this is from Windows's command line.
1. Open Windows Command Prompt (in Administrator mode, if possible).
Start - type "cmd" - (optional: right click the appearing icon - Run as administrator)
2. Pass to the R's current working directory (it can be found via "getwd()" in R's console) in the command propmt. R's current working directory contains the folder with your package source.
cd C:\Users\erdogan\Documents\Revolution
3. For the sake of argument, say the package folder was called "causfinder". Run the following command in Windows command prompt:
(be sure that you have not got any causfinder.pdf in R's working directory (You may have obtained some R-development-incompatible causfinder.pdf with some other ways outside R). If there exists, delete causfinder.pdf first.
Otherwise, you get this error: "file 'causfinder.pdf' exists; please remove it first")
R CMD Rd2pdf causfinder/
This command performs .Rd --> LateX --> .pdf process automatically. You obtain causfinder.pdf in R's working directory.
This is further described in the manual on Writing R Extensions under the section on "Processing documentation files"
I have created a basic bash function, so I can just run rdoc from my command line. It generates the Rd files, creates the pdf, and opens it. I only use it for testing, not for creating the final documentation. You can add it by adding the following function to your .bashrc (or whichever you use) file
rdoc() {
echo -e "devtools::document()" | R --no-save
rm /tmp/rdoc.pdf
R CMD Rd2pdf -o /tmp/rdoc.pdf man/*.Rd
open /tmp/rdoc.pdf
}

Resources