Skip to content
Prev 2502 / 12125 Next

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

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> 
Odesl?no: 13 March 2018 23:22
Komu: martiankabe at gmail.com; r-package-devel-bounces at r-project.org
Kopie: 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 wrote:

            
Your example never defined a variable called connectionString, so you can't pass it to a function.

 

Duncan Murdoch