Re: [R-pkg-devel] Weird error message during R CMD Check

2018-03-14 Thread martiankabe
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  
Odesláno: 13 March 2018 23:22
Komu: martiank...@gmail.com; r-package-devel-boun...@r-project.org
Kopie: r-package-devel@r-project.org
Předmět: Re: [R-pkg-devel] Weird error message during R CMD Check

 

On 13/03/2018 4:53 PM,   martiank...@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 h

Re: [R-pkg-devel] Weird error message during R CMD Check

2018-03-14 Thread Marcelino de la Cruz Rot
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, martiank...@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 
Odesláno: 13 March 2018 23:22
Komu: martiank...@gmail.com; r-package-devel-boun...@r-project.org
Kopie: r-package-devel@r-project.org
Předmět: Re: [R-pkg-devel] Weird error message during R CMD Check

  


On 13/03/2018 4:53 PM,   martiank...@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 
pas