Skip to content

Commit

Permalink
Version 5.1 - compatible with Simplace 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gk-crop committed Oct 8, 2024
1 parent 2c7d0df commit 7425347
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 60 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
^\.Rproj\.user$
^doc$
^\.github$
^log$
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
Package: simplace
Type: Package
Title: Interface to Use the Modelling Framework 'SIMPLACE'
Version: 5.0.13
Date: 2023-08-21
Version: 5.1.0
Date: 2024-10-07
Encoding: UTF-8
Author: Gunther Krauss
Maintainer: Gunther Krauss <guntherkrauss@uni-bonn.de>
Description: Interface to interact with the modelling framework 'SIMPLACE' and to
parse the results of simulations.
License: GPL-2
URL: https://github.com/gk-crop/simplace_rpkg/, https://r-forge.r-project.org/projects/simplace/
SystemRequirements: Java (>= 11.0)
SystemRequirements: Java (>= 17.0)
Imports:
rJava (>= 0.9-13)
LazyLoad: yes
VignetteBuilder: knitr
Suggests:
knitr, rmarkdown
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
7 changes: 7 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Version 5.1.0
* compatible with Simplace 5.1
* requires Java 17 or above (as Simplace 5.1 does)
* small fixes in documentation
* openProject acceps solution and project additionally as xml_document
* openProject returns not only the java session, but a list including solution and project (full path or xml text)

Version 5.0.13
* fix in package documentation

Expand Down
38 changes: 26 additions & 12 deletions R/SimplaceWrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ nullString <- rJava::.jnull(class="java/lang/String") # java null string
#' @param DataDir optional directory for data (_DATADIR_)
#' @param additionalClasspaths vector with class paths relative to InstallationDir that are to be added
#' @param javaparameters parameters that are passed to the java virtual machine
#' @param force.init (re)initialize a running JVM, see \code{\link{.jinit}}
#' @param force.init (re)initialize a running JVM, see \code{\link[rJava]{.jinit}}
#' @returns handle to the SimplaceWrapper object
#' @export
initSimplace <- function(InstallationDir = findFirstSimplaceInstallation(),
Expand Down Expand Up @@ -137,36 +137,50 @@ or required .jar files in 'lib' subfolder." ))

#' Opens a Simplace project
#'
#' Initializes a project. The absolute path to a solution file is mandatory.
#' Project file is optional.
#' Initializes a project. Solution is mandatory, project is optional.
#' Solution and project files can be specified by giving absolute paths or paths relative to
#' the simplace directory.
#' Instead of using solution and project files, one can use the content of the solution / project
#' directly as a string or a "xml_document" class.
#'
#' @param simplace handle to the SimplaceWrapper object returned by \code{\link{initSimplace}}
#' @param solution solution file with absolute path or path relative to workdir
#' @param project project file with absolute path or path relative to workdir, can be omitted to run solution only
#' @param parameterList a list with the parameter name as key and parametervalue as value
#' @returns java FWSimsession object
#' @returns invisibly a list with java FWSimsession object as well as the solution, project and parameterList
#' @seealso \code{\link{closeProject}}
#' @export
openProject <- function (simplace, solution, project=nullString, parameterList=NULL)
{
rsolution <- ifelse("xml_document" %in% class(solution), as.character(solution), solution)
rproject <- if ("xml_document" %in% class(project)){ as.character(project)} else{project}



wd <- trimws(getSimplaceDirectories(simplace)['_WORKDIR_'],"right","[/\\\\]")
if(!file.exists(solution)) {
newsol <- paste0(wd,"/",solution)
if(!file.exists(rsolution)) {
newsol <- paste0(wd,"/",rsolution)
if(file.exists(newsol)){
solution <- newsol
rsolution <- newsol
}
}

if(is.character(project) && nchar(project)>0) {
if(!file.exists(project)) {
newproj <- paste0(wd,"/",project)
if(is.character(rproject) && nchar(rproject)>0) {
if(!file.exists(rproject)) {
newproj <- paste0(wd,"/",rproject)
if(file.exists(newproj)){
project <- newproj
rproject <- newproj
}
}
}
paramObject <- parameterListToStringArray(parameterList)
invisible(rJava::.jcall(simplace, "Lnet/simplace/sim/FWSimSession;", "prepareSession", project, solution, paramObject))
invisible(
list(
session=rJava::.jcall(simplace, "Lnet/simplace/sim/FWSimSession;", "prepareSession", rproject, rsolution, paramObject),
solution=rsolution,
project=ifelse(rJava::is.jnull(project),"",rproject),
parameterList=parameterList)
)
}


Expand Down
2 changes: 1 addition & 1 deletion man/initSimplace.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions man/openProject.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 0 additions & 18 deletions man/parameterListToStringArray.Rd

This file was deleted.

18 changes: 0 additions & 18 deletions man/parameterListsToStringArray.Rd

This file was deleted.

2 changes: 1 addition & 1 deletion man/simplace.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vignettes/simplace.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ title: "Interface to use Simplace from R"
author: "Gunther Krauss"
date: "`r format(Sys.Date(),format='%B %d, %Y')`"
output:
rmarkdown::pdf_document:
number_sections: yes
rmarkdown::html_vignette:
number_sections: yes
fig-width: 7
fig-height: 6
rmarkdown::pdf_document:
number_sections: yes


vignette: >
%\VignetteIndexEntry{Simplace}
%\VignetteIndexEntry{Interface to use Simplace from R}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
Expand Down

0 comments on commit 7425347

Please sign in to comment.