[R-pkg-devel] Weird error message during R CMD Check
Michael Nelson
michael.nelson at sydney.edu.au
Thu Mar 15 07:42:57 CET 2018
I don’t think the suggestion below will work as it would need to be a connection string to a database that the winbuilder computer (and whatever account) that is running would have access to.
It would be better to use \dontrun{} so that the examples aren’t run.
This is what is done in RODBC https://cran.r-project.org/web/packages/RODBC/index.html
More fundamentally, given the cran repository policy on windows only packages, CRAN may not be the appropriate place to publish.
Michael.
On 15 Mar 2018, at 8:41 am, Marcelino de la Cruz Rot <marcelino.delacruz at urjc.es<mailto:marcelino.delacruz at urjc.es>> wrote:
It is very easy. You should define your variable connectionString before passing it to get_DB_info().
I.e.:
### ** Examples
connectionString <- WHATEVER_IS_CONNECTIONSTRING
get_DB_info(connectionString)
This would remove your error.
Cheers,
Marcelino.
El 14/03/2018 a las 22:15, martiankabe at gmail.com<mailto:martiankabe at gmail.com> escribió:
Hi Duncan,
could you help me fix this issue, please?
Below is function which creates connection string.
#' Create connection string from function parameters
#'
#' This function defines SQL Server connection string
#' from function parameters.
#' @param datasource Server name
#' @param database Database name
#' @param usr Username
#' @param pwd Password
#' @note If username and password missing or empty \strong{Integrated Security=True} is used in connection string instead.
#' @return Connection string
#' @export
#' @examples
#' set_connString("LAPTOP-USER\\SQLEXPRESS", "Database_Name")
set_connString <- function(datasource, database, usr, pwd) {
ds <- paste("Data Source=", datasource, ";", sep = "")
db <- paste("Initial Catalog=", database, ";", sep = "")
if ((missing(usr) & missing(pwd)) || (usr=="" & pwd=="")) {
last_param <- "Integrated Security=True;MultipleActiveResultSets=True;"
} else {
last_param <- paste("Integrated Security=False;", "User Id=", usr, ";", "Password=", pwd, ";", "MultipleActiveResultSets=True;", sep = "")
}
return(paste('"', ds, db, last_param, '"', sep = ""))
}
This connection string is then passed to get_DB_info function – see below.
How can I fix object ‘connectionString’ not found issue?
Thank you for any of your advice.
Martin
#' Get database info
#'
#' This function retrieves basic info about database defined
#' in SQL Server connection string.
#' @param connectionString Connection string to SQL server
#' @return Returns data.frame and data.table
#' @export
#' @examples
#' get_DB_info(connectionString)
#' @note How to set up SQL Server connection string see \link{set_connString}. Be also sure you have a permissions for access to sys.dm_db_index_usage_stats:
#' check it with SELECT * FROM sys.dm_db_index_usage_stats. If not, contact your SQL Server admin.
get_DB_info <- function(connectionString) {
options(scipen=999)
if (missing(connectionString)) {
print("Connection string is missing!")
return("Try it again")
}
# connectionString <- connectionString
pathtocsvloader <- gsub("/","\\\\",paste(system.file(package = "RSQLS")[1],"/Loader/csv_to_sql_loader.exe", sep = ""))
pathtocsvloader <- replace_spaced_words(pathtocsvloader)
pathtocsvloader <- gsub('.{1}$', '', pathtocsvloader)
# logic for pathtocsvfiles variable
pathtocsvfiles <- gsub("/","\\\\",paste(system.file(package = "RSQLS")[1],"/Data/", sep = ""))
if (!endsWith(pathtocsvfiles, "\\")) {
pathtocsvfiles <- paste(pathtocsvfiles,"\\", sep = "")
}
sqltabname <- "tempDBInfo"
sqltabname <- gsub("\\[|\\]", "", sqltabname)
if (length(strsplit(sqltabname,"\\.")[[1]]) > 1) {
sqltabname_prev <- gsub("^[^.]*.", "", sqltabname)
} else {
sqltabname_prev <- sqltabname
}
sql_tab_name <- paste('"', sqltabname, '"', sep = "") # '"dbo.CFTC_Disaggregated_Raw_test"'
sql_task <- paste('"dbinfo"', sep = "")
real_pathtocsvfile <- paste('"', pathtocsvfiles, paste(sqltabname_prev, ".csv", sep = ""),'"', sep = "")
file_to_be_deleted <- paste(pathtocsvfiles, paste(sqltabname_prev, ".csv", sep = ""), sep = "")
ss <- paste('', pathtocsvloader, " ", connectionString, " ", sql_task, " ", real_pathtocsvfile, " ", "null", sep = "")
# Call shell command
oldw <- getOption("warn")
options(warn = -1)
sc <- shell(ss)
if (file.exists(file_to_be_deleted)){
out <- data.table::fread(file_to_be_deleted, stringsAsFactors = FALSE, sep = "~", fill = TRUE)
} else{
options(warn = oldw)
stop('See the previous messages for more details.')
}
# Delete csv file
if (file.exists(file_to_be_deleted)){
invisible(file.remove(file_to_be_deleted))
} else{
options(warn = oldw)
stop('See the previous messages for more details.')
}
if( sc == 1 ) {
options(warn = oldw)
stop('See the previous messages for more details.')
} else {
options(warn = oldw)
}
return(out)
}
-----Původní zpráva-----
Od: Duncan Murdoch <murdoch.duncan at gmail.com<mailto:murdoch.duncan at gmail.com>>
Odesláno: 13 March 2018 23:22
Komu: martiankabe at gmail.com<mailto:martiankabe at gmail.com>; r-package-devel-bounces at r-project.org<mailto:r-package-devel-bounces at r-project.org>
Kopie: r-package-devel at r-project.org<mailto:r-package-devel at r-project.org>
Předmět: Re: [R-pkg-devel] Weird error message during R CMD Check
On 13/03/2018 4:53 PM, <mailto:martiankabe at gmail.com> martiankabe at gmail.com<mailto:martiankabe at gmail.com> wrote:
Hello,
I'm trying to submit my package to CRAN but receiving the following
error message.
object 'connectionString' not found
Your example never defined a variable called connectionString, so you can't pass it to a function.
Duncan Murdoch
even if it is parameter of get_DB_info(connectionString) function -
see the function definition below error message.
Please, can you help me to understand what should be fixed in the code
so that I could successfully submit my package to CRAN?
Thanks a lot for any of your help in advance.
Best,
Martin
<https://win-builder.r-project.org/incoming_pretest/180313_212715_RSQLS> https://win-builder.r-project.org/incoming_pretest/180313_212715_RSQLS
_16/00
check.log
* checking examples ...
** running examples for arch 'i386' ... ERROR
Running examples in 'RSQLS-Ex.R' failed
The error most likely occurred in:
base::assign(".ptime", proc.time(), pos = "CheckExEnv")
### Name: get_DB_info
### Title: Get database info
### Aliases: get_DB_info
### ** Examples
get_DB_info(connectionString)
Error in paste("", pathtocsvloader, " ", connectionString, " ", sql_task, :
object 'connectionString' not found
Calls: get_DB_info -> paste
Execution halted
** running examples for arch 'x64' ... ERROR
Running examples in 'RSQLS-Ex.R' failed
The error most likely occurred in:
base::assign(".ptime", proc.time(), pos = "CheckExEnv")
### Name: get_DB_info
### Title: Get database info
### Aliases: get_DB_info
### ** Examples
get_DB_info(connectionString)
Error in paste("", pathtocsvloader, " ", connectionString, " ", sql_task, :
object 'connectionString' not found
Calls: get_DB_info -> paste
Execution halted
* checking PDF version of manual ... OK
* DONE
Status: 2 ERRORs, 3 WARNINGs, 4 NOTEs
------------------------------------ get_DB_info(connectionString)
------------------------------------------------------------
#' Get database info
#'
#' This function retrieves basic info about database defined
#' in SQL Server connection string.
#' @param connectionString Connection string to SQL server
#' @return Returns data.frame and data.table
#' @export
#' @examples
#' get_DB_info(connectionString)
#' @note How to set up SQL Server connection string see
\link{set_connString}. Be also sure you have a permissions for access
to
sys.dm_db_index_usage_stats:
#' check it with SELECT * FROM sys.dm_db_index_usage_stats. If not,
contact your SQL Server admin.
get_DB_info <- function(connectionString) {
options(scipen=999)
if (missing(connectionString)) {
print("Connection string is missing!")
return("Try it again")
}
pathtocsvloader <- gsub("/","\\\\",paste(system.file(package =
"RSQLS")[1],"/Loader/csv_to_sql_loader.exe", sep = ""))
pathtocsvloader <- replace_spaced_words(pathtocsvloader)
pathtocsvloader <- gsub('.{1}$', '', pathtocsvloader)
# logic for pathtocsvfiles variable
pathtocsvfiles <- gsub("/","\\\\",paste(system.file(package =
"RSQLS")[1],"/Data/", sep = ""))
if (!endsWith(pathtocsvfiles, "\\")) {
pathtocsvfiles <- paste(pathtocsvfiles,"\\", sep = "")
}
sqltabname <- "tempDBInfo"
sqltabname <- gsub("\\[|\\]", "", sqltabname)
if (length(strsplit(sqltabname," <file://.> \\.")[[1]]) > 1) {
sqltabname_prev <- gsub("^[^.]*.", "", sqltabname)
} else {
sqltabname_prev <- sqltabname
}
sql_tab_name <- paste('"', sqltabname, '"', sep = "") #
'"dbo.CFTC_Disaggregated_Raw_test"'
sql_task <- paste('"dbinfo"', sep = "")
real_pathtocsvfile <- paste('"', pathtocsvfiles,
paste(sqltabname_prev, ".csv", sep = ""),'"', sep = "")
file_to_be_deleted <- paste(pathtocsvfiles, paste(sqltabname_prev,
".csv", sep = ""), sep = "")
ss <- paste('', pathtocsvloader, " ", connectionString, " ", sql_task, "
", real_pathtocsvfile, " ", "null", sep = "")
# Call shell command
oldw <- getOption("warn")
options(warn = -1)
sc <- shell(ss)
if (file.exists(file_to_be_deleted)){
out <- data.table::fread(file_to_be_deleted, stringsAsFactors =
FALSE, sep = "~", fill = TRUE)
} else{
options(warn = oldw)
stop('See the previous messages for more details.')
}
# Delete csv file
if (file.exists(file_to_be_deleted)){
invisible(file.remove(file_to_be_deleted))
} else{
options(warn = oldw)
stop('See the previous messages for more details.')
}
if( sc == 1 ) {
options(warn = oldw)
stop('See the previous messages for more details.')
} else {
options(warn = oldw)
}
return(out)
}
---
This email has been checked for viruses by Avast antivirus software.
<https://www.avast.com/antivirus> https://www.avast.com/antivirus
[[alternative HTML version deleted]]
______________________________________________
<mailto:R-package-devel at r-project.org> R-package-devel at r-project.org<mailto:R-package-devel at r-project.org> mailing list
<https://stat.ethz.ch/mailman/listinfo/r-package-devel> https://stat.ethz.ch/mailman/listinfo/r-package-devel
[[alternative HTML version deleted]]
______________________________________________
R-package-devel at r-project.org<mailto:R-package-devel at r-project.org> mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel
.
--
Marcelino de la Cruz Rot
Depto. de Biología y Geología
Física y Química Inorgánica
Universidad Rey Juan Carlos
Móstoles España
______________________________________________
R-package-devel at r-project.org<mailto:R-package-devel at r-project.org> mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel
[[alternative HTML version deleted]]
More information about the R-package-devel
mailing list