R: Encoding issues when installing package from Github - r

I am trying to install the dcStockR package from Github, which is an htmlwidgets wrapper around the dc.js dimensional visualization library: devtools::install_github("yutannihilation/dcStockR").
I get the following encoding error:
* installing *source* package 'dcStockR' ...
** R
Error in parse(outFile) :
C:/Users/tirthankarc/AppData/Local/Temp/Rtmpcz8pHX/devtools153839438c/yutannihilation-dcStockR-c6091c8/R/dc.R:11:59: unexpected input
10: #' #export
11: dc <- function(data, chartRecipe = c("yearlyBubbleChart",ã€
^
ERROR: unable to collate and parse R files for package 'dcStockR'
* removing 'C:/Users/tirthankarc/Documents/R/R-3.2.5/library/dcStockR'
Error: Command failed (1)
The offending lines of the file in question can be viewed here: https://github.com/yutannihilation/dcStockR/blob/master/R/dc.R#L11.
Two questions:
Is this error reproducible for others?
If so, is there a way to fix this by passing an explicit encoding option to install.packages? If not, what other options are available to fix this issue?

Related

CRAN checks errors on roxygen #examples: base::assign and missing reshape2

I am trying to push the following package to CRAN, but I keep getting an error on the check.
Error:
✓ checking R/sysdata.rda ...
WARNING
‘qpdf’ is needed for checks on size reduction of PDFs
✓ checking installed files from ‘inst/doc’ ...
✓ checking files in ‘vignettes’ ...
E checking examples (3s)
Running examples in ‘oRus-Ex.R’ failed
The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: analyseStories
> ### Title: Analysing Stories
> ### Aliases: analyseStories
>
> ### ** Examples
>
> # Transform the stories
> fileUrl <- example_stories()
> stories <- analyseStories(fileUrl, 7)
Joining, by = "word"
Joining, by = "word"
Error in loadNamespace(name) : there is no package called ‘reshape2’
Calls: analyseStories ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
Execution halted
Current problems:
The example is in orus::analyseStores(...) function.
The example actually runs and works on the pkgdown website.
The error appears only when doing devtools::check
I have tried multiple things:
This answer base::assign(".ptime", proc.time(), pos = "CheckExEnv") ERROR when using devtools::check suggested using dontrun{...}. It passes CRAN's check, but it was bounced by a person after a couple of days.
This answer R package fails devtools::check, because "could not find function" even though the function is imported in NAMESPACE suggested doing require on the missing library. I did require(reshape2) but the check still does not pass.
This answer "Could not find function" in Roxygen examples during CMD check suggests that I need to make all my functions public (exported). I don't want to do that. I tried doing orus:::some_function(...) to call to the non-exported functions inside analyseStores but it doesn't work either.
According to this one: R package build failed when checking examples the data is working and the function has the #export tag. Also, namespace is properly updated.
I have run out of options. Any idea of what is happening?
As #stefan suggested in the comments, I had to add reshape2 into the Suggested packages in the description file. I added using:
usethis::usepackage("reshape2", "Suggests")
Followed by regenerating the docs:
devtools:document()
Package is on its way to CRAN!

Error trying to download Github package on r

I am trying to download the package 'seegSDM' package but keep getting an error despite trying a couple different ways.
I am using Rx64 3.6.2 and have been using the package 'githubinstall' to try and download the package.
library(githubinstall)
gh_install_packages("seegSDM")
When I use this I get the error
"Error: unexpected string constant in:
"suppressPackageStartupMessages(.getRequiredPackages(quietly = TRUE))
tools:::makeLazyLoading("seegSDM", "C:/Users/Laptop'"
Execution halted
ERROR: lazy loading failed for package 'seegSDM'
* removing 'C:/Users/Laptop/Documents/R/win-library/3.6/seegSDM'
Error: Failed to install 'seegSDM' from GitHub:
(converted from warning) installation of package ‘C:/Users/Laptop'~1/AppData/Local/Temp/Rtmpe6YLGi/file26b07cc06130/seegSDM_0.1-9.tar.gz’ had non-zero exit status
In addition: Warning message:
In fread(download_url, sep = "\t", header = FALSE, stringsAsFactors = FALSE, :
Found and resolved improper quoting out-of-sample. First healed line 4848: <<Puriney honfleuR "Evening, honfleuR" by Seurat>>. If the fields are not quoted (e.g. field separator does not appear within any field), try quote="" to avoid this warning.
Any advice? I need to use the function neasrestLand so I can nudge points on a raster to the nearest land.
It think you need to add the organization name (SEEG-Oxford). The package installs fine with
remotes::install_github("SEEG-Oxford/seegSDM"
and I suppose it might also work with
gh_install_packages("SEEG-Oxford/seegSDM")

Using data.table in package - fail on check

I want to use data.tables as a backbone in a package that I wrote.
As I don't want to used :: all the time (and avoid the complications with [ and := operators), I include data.table as a Depends and not as an Import in DESCRIPTION to be able to use all dt functions directly.
If I build the package everything works fine but running a "check" results in the error (from DTTest.Rcheck/00install.out):
* installing *source* package ‘DTTest’ ...
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error : package ‘data.table’ required by ‘DTTest’ could not be found
Error: loading failed
Execution halted
ERROR: loading failed
The only function in this package is this
#' Creates a data.table
#'
#' #return a data.table
#' #export
#'
#' #examples
#' create_dt()
create_dt <- function() {
dt <- data.table(x = 1:10)
dt[, x_2 := x^2]
return(dt[])
}
And DESCRIPTION contains Depends: data.table, otherwise the files are the standard RStudio new package-files.
You can find the whole package here: https://github.com/DavZim/DTTest
Any ideas how to fix this?
After some helpful comments from Roland, I found the solution to my problem. It was indeed related to my .libPaths() and not with the code.
When checking the package R tried to search for the packages inside the first library in .libPaths(). As it happens, I have four paths (/usr/local/..., /usr/lib/R/site-library, /usr/lib/R/library, and /home/user/R/x86_64-pc-linux-gnu-library/3.4) and data.table is installed inside the last one.
The solution (more like a workaround at this stage) was to install data.table in the first one.
To do this, I executed R with admin privileges (sudo R in my case) and installed data.table with install.packages("data.table", lib = .libPaths()[1]).
Now the check pass as expected!

Does R's package support unicode rd file?

My platform is:
Win7 64
Rtudio
R3.1.3
devtools 1.8.0
Rxygen2 4.1.1
I am trying to make a package of my own. I need to describe the function by unicode. I used Roxygen2 to generate the Rd file. The code is very simple(I removed the real function just know how to make a package):
xxxx means comment made by unicode.
#' eastChoice
#' #param fn.kind wind xxxxxx
#' #param estChoice.Path wind
#' #return data.frame
#' #export
#' #examples
#' getIndByEastChoice("20150108.csv")
getIndByEastChoice <- function(fn.kind){
d <- data.frame(a=c(1,2,3), b=c(4,5,6))
dt <- data.table::data.table(d)
}
When I check(devtools) the R code, it always failed. The following error information is given:
* checking PDF version of manual ... WARNING
LaTeX errors when creating PDF version.
This typically indicates Rd problems.
LaTeX errors found:
! Package inputenc Error: Unicode char \u8:��<87> not set up for use with LaTeX.
See the inputenc package documentation for explanation.
Type H <return> for immediate help.
At first I thought that the Roxygen2 does not support unicode other than ASCII, but I read the Rd file generated by Roxygen2, it is OK.
And then I just use build&Reload function(using devtools), to my suprise, it passed.
And then I add more unicode comment in the R file and checked(devtools) it again. It is like the following:
#' eastChoice xxxxxx
#' #param fn.kind wind xxxxx
#' #param estChoice.Path wind xxxxxxxx
#' #return data.frame xxxxxxx
#' #export
#' #examples
#' getIndByEastChoice("20150108.csv")
getIndByEastChoice <- function(fn.kind){
d <- data.frame(a=c(1,2,3), b=c(4,5,6))
dt <- data.table::data.table(d)
}
It failed as I expected, but other information was given and seems more serious:
* checking whether package 'ftools.temp' can be installed ... ERROR
Installation failed.
See 'D:/onedrive/program/R.package/ftools.temp.Rcheck/00install.out' for details.
So I checked the log:
* installing *source* package 'ftools.temp' ...
** R
** preparing package for lazy loading
** help
*** installing help indices
wrong in gsub("&", "&", x, fixed = TRUE) : '<86>'multi byte string is wrong
* removing 'D:/onedrive/program/R.package/ftools.temp.Rcheck/ftools.temp'
And this time build&load also failed.
So I think that maybe the R does not support unicode other ASCII in its RD file? Can any one confirm it? If it is true, I will not waste my time trying to solve this problem.
#hrbrmstr
Thank you. I have tried your advice. First, I added the line "Encoding:UTF-8" in the decription file, and then saved .R and DESCRIPTION with coding UTF-8 to ensure that the encode is correct. And I run the "check " function, but I got the same error:
strsplit(txt, "\n", fixed = TRUE)���о���: �������ַ���1����UTF-8
* checking examples ... OK
* checking PDF version of manual ... WARNING
LaTeX errors when creating PDF version.
This typically indicates Rd problems.
����: ��������'"D:/R/R-31~1.3/bin/x64/Rcmd.exe" Rd2pdf --batch --no-preview --build-dir="C:/Users/kanpu/AppData/Local/Temp/RtmpgFjyKw/Rd2pdf15f2c22b7768d" --no-clean -o ftools.temp-manual.pdf "D:/onedrive/program/R.package/ftools.temp.Rcheck/ftools.temp"'��״̬��1
LaTeX errors found:
! Package inputenc Error: Unicode char \u8:��<97> not set up for use with LaTeX.
The DESCRIPTION is like this:
Package: ftools.temp
Type: Package
Title: Just try to make a package
Version: 0.1
Date: 2015-08-25
Author: None
Maintainer: no one <none#somewhere.net>
Description: Just try to make a package
License: CPL
LazyData: TRUE
Encoding:UTF-8
Depends:
data.table

Error use other library when I use Rstudio and Roxygen2 to build a package

To simplify the problem. I tried the following thing. My goal is to build a simple package which need another library.
I used RStudio and tried to create a new package, and checked the project option to "Generate document with Roxygen". And I get the following code:
#' Title just a test
#'
#' #return nothing
#' #export
#'
#' #examples
#' hello()
hello <- function() {
print("Hello, world!")
}
and I "check"ed it and "build and reload"ed it by the RStudio, all is OK.
Then I tried to add one line in the head of the code:
library("data.table")
#' Title just a test
#'
#' #return nothing
#' #export
#'
#' #examples
#' hello()
hello <- function() {
print("Hello, world!")
}
Then I failed amd get the following:
* checking whether package 'kanpu.temp' can be installed ... ERROR
Installation failed."
When I check the log, it says that:
* installing *source* package 'kanpu.temp' ...
** R
** preparing package for lazy loading
Error in library("data.table") : there is no package called 'data.table'
Error : unable to load R code in package 'kanpu.temp'
ERROR: lazy loading failed for package 'kanpu.temp'
* removing 'D:/onedrive/program/R/kanpu.temp.Rcheck/kanpu.temp'
I am sure that data.table is a existed package in my RStudio System. and also tried other package like "ggplot2", "plyr", and get the same result.
So how can I resolve this problem?
The envirement is:
Win7 64
RStudio 0.99.473
R 3.1.3 64
After checking the "Writing R Extensions", I know what's wrong with the code.
I should use "Import" or "Depends" in the "DESCRIPTION" file.
Looking at the error message, it seems that you do not have the ggplot2 package installed. This will cause an error when R reaches the line library(ggplot2).
The solution is to install that package:
install.packages("ggplot2")
However, you probably shouldn't be calling library in your packaged code. A package should make as few changes to the external environment as possible.
Instead, mark the package as required in your DESCRIPTION and make fully qualified function calls: SomePackage::someFunction().
See Hadley's pages for further information.

Resources