Skip to content

Commit

Permalink
Merge pull request #3421 from harshagr70/GH-2758-fix-tidyverse
Browse files Browse the repository at this point in the history
Fix "No Visible Binding for Global Variable" Warnings in lpjguess
  • Loading branch information
infotroph authored Feb 4, 2025
2 parents a88fa30 + ba517ac commit f184978
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 48 deletions.
2 changes: 1 addition & 1 deletion models/lpjguess/R/model2netcdf.LPJGUESS.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ model2netcdf.LPJGUESS <- function(outdir, sitelat, sitelon, start_date, end_date
PEcAn.logger::logger.error("No output files found at ", outdir)
}

lpjguess.output <- lapply(file.path(outdir, lpjguess.out.files), read.table, header = TRUE, sep = "")
lpjguess.output <- lapply(file.path(outdir, lpjguess.out.files), utils::read.table, header = TRUE, sep = "")
# n.outputs <- length(lpjguess.output)
m.to.s <- 2592000

Expand Down
28 changes: 14 additions & 14 deletions models/lpjguess/R/readStateBinary.LPJGUESS.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ readStateBinary <- function(out.path, npft){
nofpatch <- readBin(zz, integer(), 1, size = 4)

for(pat in 1:nofpatch){
Patchpft_list[[pat]] <- getClass_Patchpft()
Vegetation_list[[pat]] <- getClass_Vegetation()
Individual_list[[pat]] <- getClass_Individual(Vegetation_list[[pat]]$indv)
Soil_list[[pat]] <- getClass_Soil()
Sompool_list[[pat]] <- getClass_Sompool()
SompoolCent_list[[pat]] <- getClass_SompoolCent()
Fluxes_list[[pat]] <- getClass_Fluxes()
Patchpft_list[[pat]] <- getClass_Patchpft(zz, npft)
Vegetation_list[[pat]] <- getClass_Vegetation(zz)
Individual_list[[pat]] <- getClass_Individual(Vegetation_list[[pat]]$indv, zz)
Soil_list[[pat]] <- getClass_Soil(zz)
Sompool_list[[pat]] <- getClass_Sompool(zz)
SompoolCent_list[[pat]] <- getClass_SompoolCent(zz)
Fluxes_list[[pat]] <- getClass_Fluxes(zz)
}

# close connection to the binary state file
Expand All @@ -226,7 +226,7 @@ readStateBinary <- function(out.path, npft){


##################### Class : Patchpft #####################
getClass_Patchpft <- function(){
getClass_Patchpft <- function(zz, npft){

Patchpft <- list()

Expand Down Expand Up @@ -370,7 +370,7 @@ getClass_Patchpft <- function(){
}

##################### Class : Vegetation #####################
getClass_Vegetation <- function(){
getClass_Vegetation <- function(zz){

Vegetation <- list()
Vegetation$indv <- readBin(zz, integer(), 1, size = 4)
Expand All @@ -380,7 +380,7 @@ getClass_Vegetation <- function(){


##################### Class : Individual #####################
getClass_Individual <- function(nind){ # nind <- Vegetation$indv
getClass_Individual <- function(nind, zz){ # nind <- Vegetation$indv

Individual <- list()

Expand Down Expand Up @@ -670,7 +670,7 @@ getClass_Individual <- function(nind){ # nind <- Vegetation$indv
}

##################### Class : Soil #####################
getClass_Soil <- function(){
getClass_Soil <- function(zz){
Soil <- list()

# water content of soil layers [0=upper layer] as fraction of available water holding capacity;
Expand Down Expand Up @@ -748,7 +748,7 @@ getClass_Soil <- function(){


##################### Class : Sompool #####################
getClass_Sompool <- function(){
getClass_Sompool <- function(zz){
Sompool <- list()
npools <- 12

Expand Down Expand Up @@ -807,7 +807,7 @@ getClass_Sompool <- function(){


##################### Class : Sompool, CENTURY #####################
getClass_SompoolCent <- function(){
getClass_SompoolCent <- function(zz){
SompoolCent <- list()

# daily percolation (mm)
Expand Down Expand Up @@ -869,7 +869,7 @@ getClass_SompoolCent <- function(){


##################### Class : Fluxes #####################
getClass_Fluxes <- function(){
getClass_Fluxes <- function(zz){
Fluxes <- list()
#f.bytes <- bytes[1570:1667,]
Fluxes$f1 <- readBin(zz, double(), 1, size = 8)
Expand Down
10 changes: 6 additions & 4 deletions models/lpjguess/R/write.config.LPJGUESS.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ write.insfile.LPJGUESS <- function(settings, trait.values, rundir, outdir, run.i
guessins <- gsub("@GRID_FILE@", grid.file, guessins)

pft_names <- sapply(settings$pfts, `[[`,"name")
load(system.file("lpjguess_params.Rdata",package = "PEcAn.LPJGUESS"))

lpjguess_param_data <- PEcAn.utils::load_local(system.file("lpjguess_params.Rdata",package = "PEcAn.LPJGUESS"))
lpjguess_param_list <- lpjguess_param_data$lpjguess_param_list
# name and unit conversion
trait.values <- pecan2lpjguess(trait.values)

Expand Down Expand Up @@ -183,7 +183,9 @@ write.insfile.LPJGUESS <- function(settings, trait.values, rundir, outdir, run.i
if (end.year < 1850) {
CO2 <- data.frame(start.year:end.year, rep(280, n.year))
} else if (end.year < 2021) {
data(co2.1850.2020, package = "PEcAn.LPJGUESS")
co2_data <- new.env()
utils::data(co2.1850.2020, package = "PEcAn.LPJGUESS", envir = co2_data)
co2.1850.2020 <- co2_data$co2.1850.2020
if (start.year < 1850) {
CO2_preind <- data.frame(year = start.year:1849, ppm = rep(280, length(start.year:1849)))
CO2_postind <- co2.1850.2020[1:which(co2.1850.2020[, 1] == end.year), ]
Expand All @@ -194,7 +196,7 @@ write.insfile.LPJGUESS <- function(settings, trait.values, rundir, outdir, run.i
} else {
PEcAn.logger::logger.severe("End year should be < 2021 for CO2")
}
write.table(CO2, file = co2.file, row.names = FALSE, col.names = FALSE, sep = "\t", eol = "\n")
utils::write.table(CO2, file = co2.file, row.names = FALSE, col.names = FALSE, sep = "\t", eol = "\n")
guessins <- gsub("@CO2_FILE@", co2.file, guessins)

# write soil file path
Expand Down
30 changes: 1 addition & 29 deletions models/lpjguess/tests/Rcheck_reference.log
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,7 @@ Strong dependencies not in mainstream repositories:
* checking S3 generic/method consistency ... OK
* checking replacement functions ... OK
* checking foreign function calls ... OK
* checking R code for possible problems ... NOTE
getClass_Fluxes: no visible binding for global variable ‘zz’
getClass_Individual: no visible binding for global variable ‘zz’
getClass_Patchpft: no visible binding for global variable ‘npft’
getClass_Patchpft: no visible binding for global variable ‘zz’
getClass_Soil: no visible binding for global variable ‘zz’
getClass_Sompool: no visible binding for global variable ‘zz’
getClass_SompoolCent: no visible binding for global variable ‘zz’
getClass_Vegetation: no visible binding for global variable ‘zz’
model2netcdf.LPJGUESS: no visible binding for global variable
‘read.table’
write.insfile.LPJGUESS: no visible binding for global variable
‘lpjguess_param_list’
write.insfile.LPJGUESS: no visible global function definition for
‘data’
write.insfile.LPJGUESS: no visible binding for global variable
‘co2.1850.2020’
write.insfile.LPJGUESS: no visible global function definition for
‘write.table’
Undefined global functions or variables:
co2.1850.2020 data lpjguess_param_list npft read.table write.table zz
Consider adding
importFrom("utils", "data", "read.table", "write.table")
to your NAMESPACE file.

Found the following calls to data() loading into the global environment:
File ‘PEcAn.LPJGUESS/R/write.config.LPJGUESS.R’:
data(co2.1850.2020, package = "PEcAn.LPJGUESS")
See section ‘Good practice’ in ‘?data’.
* checking R code for possible problems ... OK
* checking Rd files ... OK
* checking Rd metadata ... OK
* checking Rd line widths ... OK
Expand Down

0 comments on commit f184978

Please sign in to comment.