CRAN Check: No repository set, so cyclic dependency check skipped [duplicate] - r

As of R 3.1.0 I get the following R check:
* checking package dependencies ... NOTE
No repository set, so cyclic dependency check skipped
I tried this advice: https://twitter.com/phylorich/status/431911660698083328
No go. I put the line options(repos="http://cran.rstudio.com/") in a .Rprofile in the package root directory. Still get the Note.
Also section 1.3.1 of Writing R Extensions states:
Some Windows users may need to set environment variable R_WIN_NO_JUNCTIONS
to a non-empty value. The test of cyclic declarations33in DESCRIPTION
files needs repositories (including CRAN) set: do this in ~/.Rprofile.
Is this possibly a result of the set environment variable R_WIN_NO_JUNCTIONS? If so how can I go about doing this? Any other possible causes of the note or suggested fixes?

From Writing R Extensions
The test of cyclic declarations in DESCRIPTION files needs repositories (including CRAN) set: do this in ~/.Rprofile, by e.g
options(repos = c(CRAN="http://cran.r-project.org"))
Recommended
User should double check if his .Rprofile is in his home and that it contains the mentioned option.
# in R session (any platform)
# where is my profile?
file.path(Sys.glob("~"),".Rprofile")
# is it there?
file.exists(file.path(Sys.glob("~"),".Rprofile"))
Or from R session using extra package:
library(pathological)
r_profile()
User should double check if the option entry is not nested in the IF condition, like in the following code:
# this will not help for R CMD check --as-cran
if(interactive()) {
options(repos = c(CRAN="http://cran.r-project.org"))
}
Dry run for any platform
Here is R script preparing easy temporary case of R package for testing, helping to faster find what is going wrong in your local usage.
This aproach helped myself to locate what was wrong in my .Rprofile file and generally can help to set up working initial state.
In best case, the check run should show only 1 NOTE about new submission.
first copy/paste the code and source it in your R session (--vanilla
preferably)
then run the command printed by the script to check test case --as-cran.
Example
# for example
R --vanilla -f makePackage.R
# here the resulting package path is as below
R --no-site-file CMD check --as-cran /tmp/pkgtest
# now see the check log
If your .Rprofile does not exist it will be created and one new line placed at the end of file in any case.
The makePackage.R script
# makePackage.R
# makes simple package for playing with check --as-cran
# copy this content to file makePackage.R
# then source it into your R --vanilla session
name <- "pkgtest"
#
# prepare and adjust package template
#
tempbase <- dirname(tempdir())
e <- new.env()
path <- dirname(tempdir())
# make simple package in path
e$fu <- function(){"Hello"}
package.skeleton(name=name,force=T,path=path,environment=e)
nil <- file.remove(
file.path(path,name,'Read-and-delete-me'),
file.path(path,name,'man',paste0(name,'-package.Rd'))
)
# adjust DESCRIPTION
D <- readLines(file.path(path,name,"DESCRIPTION"))
D[grepl("^Title: ",D)] <- "Title: Testing Skeleton"
D[grepl("^Author: ",D)] <- "Author: John Doe"
D[grepl("^Description: ",D)] <- "Description: Checking --as-cran check."
D[grepl("^Maintainer: ",D)] <- "Maintainer: John Doe <jdoe#doe.net>"
D[grepl("^License: ",D)] <- "License: GPL (>= 2)"
write(D,file.path(path,name,"DESCRIPTION"))
# make fu.Rd
write(
"\\name{fu}\\alias{fu}\\title{Prints}\\description{Prints}
\\usage{fu()}\\examples{fu()}",
file.path(path,name,'man','fu.Rd'))
#
# ensure that .Rprofile contains repos option
# add fresh new line et the end of .Rprofile
#
userRp <- file.path(Sys.glob("~"),".Rprofile")
write("options(repos = c(CRAN='http://cran.r-project.org'))",file=userRp, append=TRUE)
#
# print final message
#
msg <- sprintf("
Your test package was created in %s,
under name %s,
your user .Rprofile in %s was modified (option repos),
now check this test package from command line by command:
R --no-site-file CMD check --as-cran %s
", path, name, userRp, file.path(path,name)
)
# now is time to check the skeleton
message(msg)
Checking the package
# replace package-path by the path adviced by the sourcing the script above
R --no-site-file CMD check --as-cran package-path
There is user profile and site profile, in the approach above you bypasses site profile (in second step) by using --no-site-file option for package skeleton option.
PDF errors
You can experience PDF and latex related errors, caused very likely by missing or not complete latex instalation. Ycan use --no-manual option to skip PDF tests.
R --no-site-file CMD check --no-manual --as-cran /tmp/pkgtest

The answer above only works for Linux. On Windows I had to use a different method. When I tried to build and check my new package in R 3.2.0 on Windows 7, I got the same error:
checking package dependencies ... NOTE
No repository set, so cyclic dependency check skipped
I tried creating a file .Rprofile in my new package's root directory, but that didn't work. Instead I had to go to:
C:\Program Files\R\R-3.2.0\etc
and edit the file:
Rprofile.site
In the Rprofile.site file I added the suggested line:
options(repos = c(CRAN="http://cran.r-project.org"))
After I edited the Rprofile.site file, the NOTE
"No repository set, so cyclic dependency check skipped" finally disappeared.

Related

How to install a series of Julia packages from a file

In Python, if I install mambaforge or conda then I can make a file with extension .yml and then inside it list the name of packages I want to install alongside their specific versions. How can I do a similar way of installing packages in Julia?
I understand that if I have already installed Julia packages by addcommand in package manager, then I have a file named Project.toml which I can use to install the same packages later. However, this still does not look as good as Python's way of installing packages.
Upon further investigation I realized that to install Julia packages from an empty Prokect.tomlfile, I should add [deps]in the file followed by the name of packages I want and then give each package a uuidwhich can be found here. For example:
[deps]
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
After all , this is still tedious as it needs to find all those uuids.
How can I install packages in Julia the same way I described for Python?
Is there a particular reason that you want to write package names to a .yml file and then read the packages from there? After all, you can generate the Project file and add multiple dependencies automatically:
(#v1.8) pkg> generate MyProject # or whatever name you like
(#v1.8) pkg> activate MyProject
(MyProject) pkg> add Countries Crayons CSV # some example packages
(In recent versions of Julia, an installation prompt will appear if a package isn't already installed).
Speaking from experience, learning to use environments in Julia can be challenging to a new user, but rewarding! The documentation for Pkg.jl are helpful here.
If you are just assembling an environment for your own code, there is probably no need for you to manually edit Project.toml. On the other hand, if you are maintaining a package, you might wish to edit the file directly (e.g., for specifying compatability).
Maybe you can use this:
using TOML
using HTTP
using DataStructures
## Get the Registry.toml file if it already doesn't exist in the current directory
function raed_reg()
if !isfile("Registry.toml")
HTTP.download(
"https://raw.githubusercontent.com/JuliaRegistries/General/master/Registry.toml",
"Registry.toml"
)
end
reg = TOML.parsefile("Registry.toml")["packages"]
return reg
end
## Find the UUID of a specific package from the Registry.toml file
function get_uuid(pkg_name)
reg = raed_reg()
for (uuid, pkg) in reg
if pkg["name"] == pkg_name
return uuid
end
end
end
## Create a dictionary for the gotten UUIDs, by setting the name = UUID and convert it to a project.toml file
function create_project_toml(Pkgs::Vector{String})
reg = raed_reg()
pkgs_names_uuid = OrderedDict{AbstractString, AbstractString}()
pkgs_names_uuid["[deps]"] = ""
for pkg in Pkgs
_uuid = get_uuid(pkg)
pkgs_names_uuid[pkg] = _uuid
end
open("project.toml", "w") do io
TOML.print(io, pkgs_names_uuid)
end
end
## Test on the packages "ClusterAnalysis" and "EvoTrees"
create_project_toml(["ClusterAnalysis", "EvoTrees"])

"R CMD check" throws warning on use of 'devtools::test()', but allows 'test()', but need to use full function name

I'm running my package through R CMD check and the only (remaining) warning is the following:
W checking for unstated dependencies in 'tests' (4.4s)
'::' or ':::' import not declared from: 'devtools'
After getting confused for a long time about this seemingly nonsensical warning, I realized it's coming from my "test manager" script (see reason for its need below). This is file pkg/tests/testthat.R, while the tests themselves are in pkg/tests/testthat/.
# testthat.R
sink(stderr(), type = "output")
x <- tryCatch(
{
x <- data.frame(devtools::test()) # here's the problem!
as.numeric(sum(x$failed) > 0)
},
error = function(e) {
1
}
)
sink(NULL, type = "output")
cat(1)
If I comment out this entire file, the R CMD check warning vanishes.
And then the weird part: if I replace devtools::test() with just test(), the R CMD check warning vanishes.
However, the purpose of this "manager" script is to be to be called (via Rscript) by a git pre-commit hook. This way, I can run all my tests to ensure the commit is stable. Due to this, I can't use test(), since devtools isn't loaded when the script is run via Rscript.
I tried a few things to satisfy both R CMD check and being called by Rscript:
Using library(devtools) doesn't work (throws a package not found error);
Moving testthat.R out of the /tests/ folder and into the top-level. This kills the R CMD check warning, but it now instead throws a note: Non-standard file/directory found at top level: 'testthat.R', so not exactly satisfactory (especially since keeping it in the /tests/ directory seems more logically consistent);
Testing for a function which has been apparently loaded by R CMD check to determine behavior. Since using a naked test() works, I assumed devtools was loaded, so prepended the following to the file (and used runTests on the problematic line). The logic being, if we can find test(), use it. If we can't, then this probably isn't R CMD check, so we can use the full name.
if (length(find("test")) == 0) {
runTests <- devtools::test()
} else {
runTests <- test()
}
Unfortunately, this just made things worse: the warning remains and we also get an error on the if-else block:
> if (length(find("test")) == 0) {
+ runTests <- devtools::test()
+ } else {
+ runTests <- test()
+ }
Error in loadNamespace(name) : there is no package called 'devtools'
Calls: :: ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
Why devtools::test() throws an error here and just a warning on the problematic line is beyond me.
Similarly, using testthat::skip(). Also doesn't work.
So, what can I do to satisfy both R CMD check and being called by Rscript? Is there a way to tell R CMD check to ignore this file?
For the record, this is my git pre-commit hook, in case it can be reformulated to solve this problem some other way
#!/bin/sh
R_USER="D:/Users/wasabi/Documents"
export R_USER
# check that Rscript is accessible via PATH; fail otherwise
command -v Rscript >/dev/null || {
echo "Rscript must be accessible via PATH. Commit aborted.";
exit 1;
};
# check whether there are unstaged changes. If so, stash them.
# This allows the tests to run only on previously committed or
# indexed (added on this commit) changes.
hasChanges=$(git diff)
if [ -n "$hasChanges" ]; then
git stash push --keep-index
fi
exitCode=$(Rscript tests/testthat.R)
# remember to unstash any unstaged changes
if [ -n "$hasChanges" ]; then
git stash pop
fi
exit $exitCode
The solution is to simply add tests/testthat.R to .Rbuildignore (either by hand in the form of a regular expression or using usethis::use_build_ignore("tests/testthat.R")).
If you actually run R CMD check, the warning will still appear (since it runs on the source files, and therefore ignores .Rbuildignore, unless you run it on the binary itself).
But the "Check Package" command in RStudio relies on devtools::check(), which builds the package first and then checks the binary, therefore not getting the error. And since that's how my team and I will actually be running the checks, it's sufficient.
Solution inspired by this question.

R CMD Check, '--no-manual': How to change this option?

There are similar questions R create reference manual with R CMD check. However, I still can fix my problem with R CMD Check.
When R CMD Check, it indicates:
-- R CMD check results ----------------------------------- chest 0.0.1.0000 ----
Duration: 1m 32.1s
0 errors v | 0 warnings v | 0 notes v
R CMD check succeeded
But without producing the Reference Manual. When I check the log file, it says * using options '--no-manual --as-cran'. I have tried to change the Project option, then Build tools, then Check package R CMD check additional options without any success. What should I do to turn off --no-manual option? Thanks.
You appear to be running devtools::check() from the RStudio menus. I don't know if there's a way to set these options from the menus, but you can set them from the command line by running
devtools::check(manual = TRUE)
You can run R CMD check pkgtarfile, link, directly in a terminal, where pkgtarfile is the 'tar' file you obtain with devtools::build() or R CMD build pkgdirs. R CMD check generates the pdf manual by default and can be found in the folder pkgname.Rcheck.

compile R package in R console using Rtools

To avoid the irregular parameter error caused by the directory including space and set workspace and tool path at once, I tried to compile R package in R console. My goal is compile the new version of "text2vec-0.4" which downloaded from https://github.com/dselivanov/text2vec/tree/0.4
setwd("E:/packbuild/")
builder <- "D:/Program Files/R/R-3.3.1/bin/x64/Rcmd.exe"
para <- "INSTALL --build"
packname <- "text2vec-0.4"
system(paste(shQuote(builder), para, packname, sep = " "), wait = FALSE)
When I run this program, it runs “successfully” no errors or warnings, but when I check the workspace"E:/packbuild/", there is no zip files generated and no new files installed in the R library. Rtools has completely installed in “D:/Rtools/” and its default path set has done.
Does Rtools can’t call by a meta program like this?
Or if we use command line, and don’t write directory of “Rcmd” into
path, how to do is right?

NOTE in R CRAN Check: No repository set, so cyclic dependency check skipped

As of R 3.1.0 I get the following R check:
* checking package dependencies ... NOTE
No repository set, so cyclic dependency check skipped
I tried this advice: https://twitter.com/phylorich/status/431911660698083328
No go. I put the line options(repos="http://cran.rstudio.com/") in a .Rprofile in the package root directory. Still get the Note.
Also section 1.3.1 of Writing R Extensions states:
Some Windows users may need to set environment variable R_WIN_NO_JUNCTIONS
to a non-empty value. The test of cyclic declarations33in DESCRIPTION
files needs repositories (including CRAN) set: do this in ~/.Rprofile.
Is this possibly a result of the set environment variable R_WIN_NO_JUNCTIONS? If so how can I go about doing this? Any other possible causes of the note or suggested fixes?
From Writing R Extensions
The test of cyclic declarations in DESCRIPTION files needs repositories (including CRAN) set: do this in ~/.Rprofile, by e.g
options(repos = c(CRAN="http://cran.r-project.org"))
Recommended
User should double check if his .Rprofile is in his home and that it contains the mentioned option.
# in R session (any platform)
# where is my profile?
file.path(Sys.glob("~"),".Rprofile")
# is it there?
file.exists(file.path(Sys.glob("~"),".Rprofile"))
Or from R session using extra package:
library(pathological)
r_profile()
User should double check if the option entry is not nested in the IF condition, like in the following code:
# this will not help for R CMD check --as-cran
if(interactive()) {
options(repos = c(CRAN="http://cran.r-project.org"))
}
Dry run for any platform
Here is R script preparing easy temporary case of R package for testing, helping to faster find what is going wrong in your local usage.
This aproach helped myself to locate what was wrong in my .Rprofile file and generally can help to set up working initial state.
In best case, the check run should show only 1 NOTE about new submission.
first copy/paste the code and source it in your R session (--vanilla
preferably)
then run the command printed by the script to check test case --as-cran.
Example
# for example
R --vanilla -f makePackage.R
# here the resulting package path is as below
R --no-site-file CMD check --as-cran /tmp/pkgtest
# now see the check log
If your .Rprofile does not exist it will be created and one new line placed at the end of file in any case.
The makePackage.R script
# makePackage.R
# makes simple package for playing with check --as-cran
# copy this content to file makePackage.R
# then source it into your R --vanilla session
name <- "pkgtest"
#
# prepare and adjust package template
#
tempbase <- dirname(tempdir())
e <- new.env()
path <- dirname(tempdir())
# make simple package in path
e$fu <- function(){"Hello"}
package.skeleton(name=name,force=T,path=path,environment=e)
nil <- file.remove(
file.path(path,name,'Read-and-delete-me'),
file.path(path,name,'man',paste0(name,'-package.Rd'))
)
# adjust DESCRIPTION
D <- readLines(file.path(path,name,"DESCRIPTION"))
D[grepl("^Title: ",D)] <- "Title: Testing Skeleton"
D[grepl("^Author: ",D)] <- "Author: John Doe"
D[grepl("^Description: ",D)] <- "Description: Checking --as-cran check."
D[grepl("^Maintainer: ",D)] <- "Maintainer: John Doe <jdoe#doe.net>"
D[grepl("^License: ",D)] <- "License: GPL (>= 2)"
write(D,file.path(path,name,"DESCRIPTION"))
# make fu.Rd
write(
"\\name{fu}\\alias{fu}\\title{Prints}\\description{Prints}
\\usage{fu()}\\examples{fu()}",
file.path(path,name,'man','fu.Rd'))
#
# ensure that .Rprofile contains repos option
# add fresh new line et the end of .Rprofile
#
userRp <- file.path(Sys.glob("~"),".Rprofile")
write("options(repos = c(CRAN='http://cran.r-project.org'))",file=userRp, append=TRUE)
#
# print final message
#
msg <- sprintf("
Your test package was created in %s,
under name %s,
your user .Rprofile in %s was modified (option repos),
now check this test package from command line by command:
R --no-site-file CMD check --as-cran %s
", path, name, userRp, file.path(path,name)
)
# now is time to check the skeleton
message(msg)
Checking the package
# replace package-path by the path adviced by the sourcing the script above
R --no-site-file CMD check --as-cran package-path
There is user profile and site profile, in the approach above you bypasses site profile (in second step) by using --no-site-file option for package skeleton option.
PDF errors
You can experience PDF and latex related errors, caused very likely by missing or not complete latex instalation. Ycan use --no-manual option to skip PDF tests.
R --no-site-file CMD check --no-manual --as-cran /tmp/pkgtest
The answer above only works for Linux. On Windows I had to use a different method. When I tried to build and check my new package in R 3.2.0 on Windows 7, I got the same error:
checking package dependencies ... NOTE
No repository set, so cyclic dependency check skipped
I tried creating a file .Rprofile in my new package's root directory, but that didn't work. Instead I had to go to:
C:\Program Files\R\R-3.2.0\etc
and edit the file:
Rprofile.site
In the Rprofile.site file I added the suggested line:
options(repos = c(CRAN="http://cran.r-project.org"))
After I edited the Rprofile.site file, the NOTE
"No repository set, so cyclic dependency check skipped" finally disappeared.

Resources