From eb3f552028ef26ad435296d0968c094b5eb00c33 Mon Sep 17 00:00:00 2001 From: Matthew-Supernaw-NOAA Date: Fri, 3 May 2024 12:33:30 -0400 Subject: [PATCH] replace 'function' with 'func' When accessing the element log[[i]]$function throws a error in R. Replaced element name with 'func'. --- inst/include/common/fims_log.hpp | 2 +- test/test.R | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/inst/include/common/fims_log.hpp b/inst/include/common/fims_log.hpp index 3ee439e..58cd156 100644 --- a/inst/include/common/fims_log.hpp +++ b/inst/include/common/fims_log.hpp @@ -80,7 +80,7 @@ struct LogEntry { ss << "\"user\" : " << "\"" << this->user << "\",\n"; ss << "\"wd\" : " << "\"" << this->wd << "\",\n"; ss << "\"file\" : " << "\"" << this->file << "\",\n"; - ss << "\"function\" : " << "\"" << this->func << "\",\n"; + ss << "\"func\" : " << "\"" << this->func << "\",\n"; ss << "\"line\" : " << "\"" << this->line << "\"\n"; return ss.str(); } diff --git a/test/test.R b/test/test.R index 0cc244a..4ddfbbb 100644 --- a/test/test.R +++ b/test/test.R @@ -4,6 +4,8 @@ library(TMB) library(Rcpp) library(ModularTMBExample) +library(jsonlite) + #get the Rcpp module g<-Rcpp::Module(module = "growth",PACKAGE = "ModularTMBExample") @@ -82,3 +84,21 @@ obj$report() print("final gradient:") print(rep$gradient.fixed) cat(g$GetLog()) + + +fims_log<-fromJSON(g$GetLog(),simplifyVector = FALSE) +for(i in 1:length(fims_log)){ + print(fims_log[[i]]) + } + +for(i in 1:length(fims_log)){ + print(fims_log[[i]]$user) + print(fims_log[[i]]$timestamp) + print(fims_log[[i]]$id) + print(fims_log[[i]]$level) + print(fims_log[[i]]$message) + print(fims_log[[i]]$line) + print(fims_log[[i]]$file) + print(fims_log[[i]]$func) + cat("\n\n") +}