R/create.geotop.inpts.keywords.R

Defines functions create.geotop.inpts.keyword

Documented in create.geotop.inpts.keyword

# TODO: Add comment
# 
# Author: ecor
###############################################################################
#### color.bar
NULL
#'
#' Creates an 'geotop.inpts'  files the keyword and their values of a date.frame like the one returned by \code{\link{declared.geotop.inpts.keywords}}
#' 
#' 
#' 
#' @param df data frame returend by \code{\link{declared.geotop.inpts.keywords}}
#' @param file connetion or file name where to write 'df'
#' @param wpath complere path to \code{file} (optional). Default is \code{NULL}. 
#' @param comment.lines string or vector of strings to add as comments for each keyword. If it is \code{NULL} the comment lines are omitted. 
#' @param header string or vector of strings to add as a header. If it is \code{NULL} the header is omitted. 
#' @param ... further arguments for \code{\link{writeLines}}
#' 
#'  
### @details The arguments \code{comment.lines} and \code{header} are set equal to \code{"default"} if not indicated (see the function usage). 
### In this case they will be replaced by the character string: \n
### \n
### \code{paste("!",c(""," insert optional comment for the keyword below",""),sep="")} for  \code{comment.lines} 
### and 
### c("",paste("!",file,"automatically generated by create.geotop.inpts.keyword (\'geotobricks\' CRAN R Paackage)"),"","")
### for \code{header}
#' 
#' @details In case \code{comment.lines} and \code{header} are set equal to \code{"default"}, 
#' they are suitably modified within the function code. 
#' See the example output.
#' 
#' 
#' @export
#' @examples 
#' 
# library(stringr)
#' library(geotopbricks)
#' 
#' #Simulation working path
#' wpath <- 'http://www.rendena100.eu/public/geotopbricks/simulations/panola13_run2xC_test3'
#' df <- declared.geotop.inpts.keywords(wpath=wpath)
#' create.geotop.inpts.keyword(df=df)
#' 
#' 
#' 
#' @seealso \code{\link{writeLines}},\code{\link{declared.geotop.inpts.keywords}}
#' 
#' 






create.geotop.inpts.keyword <- function(df,file='geotop.inpts.copy',wpath=NULL,
		comment.lines="default",
		header="default",...) {

	
	if (comment.lines=="default") comment.lines <- paste("!",c(""," insert optional comment for the keyword below",""),sep="")
	if (header=="default") heeader <- c("",paste("!",file,"automatically generated by create.geotop.inpts.keyword (\'geotobricks\' CRAN R Paackage)"),"","")
	
	condition_wpath <- (!is.null(wpath) & !is.na(wpath) & wpath!=FALSE)
	if (length(condition_wpath)==0)  condition_wpath=FALSE
	if (condition_wpath)  file <- paste(wpath,file,sep="/")
	
	
	df <- df[df$Keyword!="",]
	
	lines <- paste(df$Keyword,"=",df$Value)
	
	if (!is.null(comment.lines)) {
		
		NLINES <- (length(comment.lines)+1)*length(lines)
		
		lines_temp <- lines 
		lines <- rep(c(comment.lines,"KEYWORD"),length(lines_temp))
		lines[lines=="KEYWORD"] <- lines_temp
		
	}
	
	if (!is.null(header)) lines <- c(header,lines)
	
	base::writeLines(lines,con=file,sep="\n",...)
	
	return(0)
	
}

Try the geotopbricks package in your browser

Any scripts or data that you put into this service are public.

geotopbricks documentation built on May 29, 2017, 9:48 a.m.