Skip to content

Commit d6f677c

Browse files
author
Junbin Zhao
committed
refined the package according to recommendations of package check
1 parent d8feed0 commit d6f677c

14 files changed

+47
-43
lines changed

.Rbuildignore

+4
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
^\.Rproj\.user$
33
^README\.Rmd$
44
^\.travis\.yml$
5+
^.*\.zip$
6+
^CONTRIBUTING\.md$
7+
^paper\.bib$
8+
^paper\.md$

DESCRIPTION

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
Package: FluxCalR
22
Type: Package
33
Title: Calculate CO2 and CH4 gas fluxes measured with static chamber method
4-
Version: 0.1.0
4+
Version: 0.2.0
55
Author: Junbin Zhao
66
Maintainer: Junbin Zhao <[email protected]>
77
Year: 2018
88
Description: This R package is used to calculate CO2 and CH4 gas fluxes measured with static chamber method. It provide a easy way to calculate multiple flux measurements from one data file. The format of data input are specialized to that of from Los Gatos Research (LGR) Ultraportable Gas Analyzers <http://www.lgrinc.com/analyzers/ultraportable/>. A function is also provided to load and convert data from other sources (e.g. LICOR) into the format that is compatible with the flux calculation fuction.
9-
Depends: R (>= 3.4.1)
10-
License: MIT
9+
Depends: R (>= 3.4.0)
10+
License: MIT + file LICENSE
1111
Encoding: UTF-8
1212
LazyData: true
13-
Imports: dplyr, lubridate, assertthat, magrittr
13+
Imports: dplyr, lubridate, assertthat, magrittr, threadr, utils
1414
RoxygenNote: 7.0.0
1515
Suggests:
1616
knitr,

R/FluxCal.R

+14-14
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#' @description A function to calculate CO2 and CH4 gas fluxes from the data loaded by the function \code{\link{LoadLGR}}
44
#' or \code{\link{LoadOther}}.
55
#' It takes a time cue data frame (argument \code{df_cue}), either created by the function \code{\link{SelCue}} or prepared by the
6-
#' user following the format of example files "Time & Ta_1.csv" and "Time & Ta_2.csv" at
6+
#' user following the format of example files "Time_&_Ta_1.csv" and "Time_&_Ta_2.csv" at
77
#' https://github.com/junbinzhao/FluxCalR/tree/master/inst/extdata
88
#' to separate the measurements and then calculate the fluxes for all the measurements at once.
99
#' Note that the header for the time cue column must be either \strong{"Start"} or \strong{"End"}.
@@ -20,7 +20,7 @@
2020
#' @param df_cue A data frame that includes "Start" and/or "End" time (HH:MM:SS) of each measurement.
2121
#' The header for the time must be either \strong{"Start"} or \strong{"End"}. This data frame can either be created by the
2222
#' function \code{\link{SelCue}} or be prepared by the user
23-
#' (see example files "Time & Ta_1.csv" and "Time & Ta_2.csv" at https://github.com/junbinzhao/FluxCalR/tree/master/inst/extdata).
23+
#' (see example files "Time_&_Ta_1.csv" and "Time_&_Ta_2.csv" at https://github.com/junbinzhao/FluxCalR/tree/master/inst/extdata).
2424
#' @param cue_type A string, either "Start", "End" (default) or "Start_End", indicates if start, end or both time in the
2525
#' data frame assigned to \code{df_cue} will be used as the cues . When "Start_End" is chosen, both "Start" and "End" columns
2626
#' have to be present in the data frame for \code{df_cue} and the flux with the largest R2 within the range will be calculated
@@ -29,7 +29,7 @@
2929
#' that need to be passed along to the final output data frame. Default: NULL.
3030
#' @param df_Ta A data frame contains a column "Ta" with the air temperature values (ideally, this is temperature measured inside
3131
#' of the chamber during the flux measurement; unit: degree C. This can be the same data frame as in \code{df_cue}.
32-
#' See example files "Time & Ta_1.csv" and "Time & Ta_2.csv" at https://github.com/junbinzhao/FluxCalR/tree/master/inst/extdata).
32+
#' See example files "Time_&_Ta_1.csv" and "Time_&_Ta_2.csv" at https://github.com/junbinzhao/FluxCalR/tree/master/inst/extdata).
3333
#' Note the row number of the data frame must be the same as the number of flux measurements.
3434
#' Default: NULL, then the temperature used is either the average ambient air temperature measured by the LGR analyzer
3535
#' (column "AmbT_C") or, if the data measured by other analyzers, Ta input from function \code{\link{LoadOther}}.
@@ -77,7 +77,7 @@
7777
#' Flux_output1
7878
#'
7979
#' # input the time cues from a prepared file and calculate the fluxes over a 3-minute window
80-
#' Example_cue1 <- system.file("extdata", "Time & Ta_1.csv", package = "FluxCalR") # directory of the file with time cues and Ta
80+
#' Example_cue1 <- system.file("extdata", "Time_&_Ta_1.csv", package = "FluxCalR") # directory of the file with time cues and Ta
8181
#' Time_Ta1 <- read.csv(Example_cue1)
8282
#' head(Time_Ta1)
8383
#' Flux_output2 <- FluxCal(data = Flux_lgr,
@@ -102,7 +102,7 @@
102102
#' Ta = "Tem_C")
103103
#'
104104
#' # input the time cues from a prepared file and calculate the fluxes over a 3-minute window
105-
#' Example_cue2 <- system.file("extdata", "Time & Ta_2.csv", package = "FluxCalR") # directory of the file with time cues and Ta
105+
#' Example_cue2 <- system.file("extdata", "Time_&_Ta_2.csv", package = "FluxCalR") # directory of the file with time cues and Ta
106106
#' Time_Ta2 <- read.csv(Example_cue2)
107107
#' head(Time_Ta2)
108108
#' Flux_output3 <- FluxCal(data = Flux_other,
@@ -171,7 +171,7 @@ FluxCal <- function(data,
171171
if (cue_type == "End"){ ### if end time is given
172172
df_cue$End <- lubridate::ymd_hms(paste(date_m,df_cue$End,sep = "_")) # add date of measurement to time cues
173173
# match the closest
174-
for(i in 1:nrow(df_cue)){
174+
for(i in seq_len(nrow(df_cue))){
175175
In[i] <- threadr::which_closest(data$Time,df_cue$End[i])
176176
}
177177
In1 <- In # start moving
@@ -186,7 +186,7 @@ FluxCal <- function(data,
186186
if (cue_type == "Start"){ ### if start time is given
187187
df_cue$Start <- lubridate::ymd_hms(paste(date_m,df_cue$Start,sep = "_")) # add date of measurement to time cues
188188
# match the closest
189-
for(i in 1:nrow(df_cue)){
189+
for(i in seq_len(nrow(df_cue))){
190190
In[i] <- threadr::which_closest(data$Time,df_cue$Start[i])
191191
}
192192
In1 <- In+ext*win_f
@@ -201,14 +201,14 @@ FluxCal <- function(data,
201201
df_cue$End <- lubridate::ymd_hms(paste(date_m,df_cue$End,sep = "_")) # add date of measurement to time cues
202202
df_cue$Start <- lubridate::ymd_hms(paste(date_m,df_cue$Start,sep = "_"))
203203
# match the closest
204-
for(i in 1:nrow(df_cue)){
204+
for(i in seq_len(nrow(df_cue))){
205205
In[i] <- threadr::which_closest(data$Time,df_cue$End[i])
206206
}
207207
In1 <- In
208208
# recycle In
209209
In <- vector()
210210
#
211-
for(i in 1:nrow(df_cue)){
211+
for(i in seq_len(nrow(df_cue))){
212212
In[i] <- threadr::which_closest(data$Time,df_cue$Start[i])
213213
}
214214
In2 <- In+win_f
@@ -235,7 +235,7 @@ FluxCal <- function(data,
235235
dft <- data.frame(matrix(0,nrow(df_cue),9)) # for record the data
236236
names(dft) <- c("Num","Date","Start","End","Gas","Slope","R2","Ta","Index")
237237
########## 1. calculate the max R2 and slopes of the regression winthin the window with an extended range
238-
for (a in 1:nrow(df_cue)){
238+
for (a in seq_len(nrow(df_cue))){
239239
# the window is moving backwards from the end point
240240
for (b in In1[a]:In2[a]){
241241
if (flux == "CO2"){ # for CO2
@@ -307,7 +307,7 @@ FluxCal <- function(data,
307307
xlab="Time",bty="n", xaxt="n",
308308
ylim=ylim),silent=TRUE)
309309
# plot the regression lines
310-
for (i in 1:nrow(dft)){
310+
for (i in seq_len(nrow(dft))){
311311
Slm <- try(lm(data[(dft[i,"Index"]-win_f):dft[i,"Index"],var]~
312312
data$Row[(dft[i,"Index"]-win_f):dft[i,"Index"]]),silent=TRUE)
313313
try(lines(data$Row[(dft[i,"Index"]-win_f):dft[i,"Index"]], Slm$fitted.values,
@@ -330,10 +330,10 @@ FluxCal <- function(data,
330330
###### calculate the flux using the function and, if required, output the file and plot the result ------------------
331331
if (check_plot == TRUE){ # if the checking plot is needed, create a window for plotting
332332
if (cal == "CO2_CH4"){ # both CO2 and CH4 are calculated, plot 2 graphs
333-
x11(width = 16,height = 12)
333+
dev.new(width = 16,height = 12,noRStudioGD=TRUE)
334334
par(mfrow=c(2,1),mar=c(2,1,2,1),xpd=NA,oma=c(4,4,1,1))
335335
} else { # only CO2 or CH4 is calculated, plot 1 graph
336-
x11(width = 16,height = 5)
336+
dev.new(width = 16,height = 5,noRStudioGD=TRUE)
337337
par(mar=c(0.5,1,0.5,1),xpd=NA,oma=c(4,4,1,1))
338338
}
339339
}
@@ -349,7 +349,7 @@ FluxCal <- function(data,
349349
}
350350
# check if the data frame needs to be output as a file
351351
if (assertthat::is.string(output)){
352-
write.csv(dfoutput,file = output,row.names = F)
352+
utils::write.csv(dfoutput,file = output,row.names = F)
353353
}
354354

355355
return(dfoutput)

R/Load.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#'
77
#' @param file A string contains the directory path and file name of the raw data.
88
#' The data should be provided as what is exported from the LGR analyzer.
9-
#' @param Time_format A string indicates the format of timestamps. Default: "mdy_HMS".
9+
#' @param time_format A string indicates the format of timestamps. Default: "mdy_HMS".
1010
#' It also takes the format "dmy_HMS" or "ymd_HMS", depending on the timestamps output from the analyzer.
1111
#'
1212
#' @return A data frame with all data in the right format for the functions \code{\link{SelCue}} and \code{\link{FluxCal}}.
@@ -26,7 +26,7 @@ LoadLGR <- function(file,
2626
# argument check
2727
time_format <- match.arg(time_format,c("mdy_HMS","dmy_HMS","ymd_HMS"))
2828
# Load the raw data after deleting the text massages at the beginning and the end of each raw data file generate by LGR
29-
flux <- read.table(file, sep= ",", header = TRUE,skip = 1,fill = TRUE,stringsAsFactors = FALSE)
29+
flux <- utils::read.table(file, sep= ",", header = TRUE,skip = 1,fill = TRUE,stringsAsFactors = FALSE)
3030
flux <- subset(flux,!is.na(flux[,2])) # remove the comments generated by LGR
3131
# replace the time with "lubridated" time with different format
3232
flux$Time <- try(suppressWarnings(lubridate::parse_date_time(flux$Time,orders = time_format)),
@@ -94,7 +94,7 @@ LoadOther <- function(file,
9494
# define the pipe from the package "magrittr"
9595
`%>%` <- magrittr::`%>%`
9696
# Load the raw data after deleting the text massages at the beginning and the end of each raw data file
97-
flux1 <- read.table(file, sep= sep, header = TRUE,skip = skip,fill = TRUE,stringsAsFactors = FALSE,...)
97+
flux1 <- utils::read.table(file, sep= sep, header = TRUE,skip = skip,fill = TRUE,stringsAsFactors = FALSE,...)
9898
flux1 <- subset(flux1,!is.na(flux1[,2])) # remove the comments generated by analyzer
9999
# replace the time with "lubridated" time with different format
100100
if (time_format=="HMS"){ # if only time is provided, then combine the time with date first

R/Select time cues.R R/Select_time_cues.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#' clicking the corresponding start or end measurement points on the interactive graphs generated by the function.
55
#' The data frame returned from this function can be assigned to the argument \code{df_cue} in the \code{\link{FluxCal}} function.
66
#' Note that the time cue data frame can also be prepared by the user independent of this function following the format of
7-
#' "Time & Ta_1.csv" and "Time & Ta_2.csv" at https://github.com/junbinzhao/FluxCalR/tree/master/inst/extdata).
7+
#' "_1.csv" and "_2.csv" at https://github.com/junbinzhao/FluxCalR/tree/master/inst/extdata).
88
#'
99
#' @param data A dataframe generated by the function \code{\link{LoadLGR}} or \code{\link{LoadOther}}.
1010
#'
@@ -81,7 +81,7 @@ SelCue <- function(data,
8181
# plot flux vs time for locating the peaks and valleys
8282
In <- c() # create a variable as Index
8383
for (i in 1:spt){
84-
x11(width = 16,height = 10)
84+
dev.new(width = 16,height = 10,noRStudioGD=TRUE)
8585
with(data[c(((i-1)*nr/spt)+1):c(i*nr/spt),],
8686
plot(Time,flux_plot,
8787
ylab = ylab,
@@ -110,7 +110,7 @@ SelCue <- function(data,
110110

111111
# output the time cues if necessary
112112
if (assertthat::is.string(save)){
113-
write.csv(Time_q,file = save,row.names = F)
113+
utils::write.csv(Time_q,file = save,row.names = F)
114114
}
115115
return(Time_q)
116116
}

README.Rmd

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Then, install the `FluxCalR` package (with vignettes) in R by:
4848
```r
4949
remotes::install_github("junbinzhao/FluxCalR",build_vignettes = TRUE)
5050
```
51-
The functioning of the package is based on other R packages: `dplyr`, `lubridate`, `assertthat`, `magrittr` and they will/must be installed before using the functions in the `FluxCalR` package.
51+
The functioning of the package is based on other R packages: `dplyr`, `lubridate`, `assertthat`, `magrittr`,`threadr` and they will/must be installed before using the functions in the `FluxCalR` package.
5252

5353
*Note: in case the installation fails in Rstudio, try to install the package in the original R program and then load the package in Rstudio.*
5454

@@ -93,7 +93,7 @@ knitr::include_graphics("vignettes/images/timecue.png") # add time cue graph wit
9393
time_cue <- read.csv("vignettes/Time_cue.csv")
9494
```
9595

96-
This is how the "time_cue" data frame looks like. Instead of having it created by the function `SelCue()`, one can also manually prepare such a file and load it into R as a data frame. But the column name ("End" or "Start") and time format must be in line with the "time_cue" here, or see example files "Time & Ta_1.csv" and "Time & Ta_2.csv" at https://github.com/junbinzhao/FluxCalR/tree/master/inst/extdata).
96+
This is how the "time_cue" data frame looks like. Instead of having it created by the function `SelCue()`, one can also manually prepare such a file and load it into R as a data frame. But the column name ("End" or "Start") and time format must be in line with the "time_cue" here, or see example files "Time_&_Ta_1.csv" and "Time_&_Ta_2.csv" at https://github.com/junbinzhao/FluxCalR/tree/master/inst/extdata).
9797

9898
```{r}
9999
time_cue

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ remotes::install_github("junbinzhao/FluxCalR",build_vignettes = TRUE)
9999
```
100100

101101
The functioning of the package is based on other R packages: `dplyr`,
102-
`lubridate`, `assertthat`, `magrittr` and they will/must be installed
103-
before using the functions in the `FluxCalR` package.
102+
`lubridate`, `assertthat`, `magrittr`,`threadr` and they will/must be
103+
installed before using the functions in the `FluxCalR` package.
104104

105105
*Note: in case the installation fails in Rstudio, try to install the
106106
package in the original R program and then load the package in Rstudio.*
@@ -130,7 +130,7 @@ library(FluxCalR)
130130
# get the directory of the example LGR raw data
131131
example_data1 <- system.file("extdata", "Flux_example_1_LGR.txt", package = "FluxCalR")
132132
example_data1 # check the directory
133-
#> [1] "C:/Users/Zhao/Documents/R/win-library/3.6/FluxCalR/extdata/Flux_example_1_LGR.txt"
133+
#> [1] "C:/Users/juzh/Documents/R/R-3.6.1/library/FluxCalR/extdata/Flux_example_1_LGR.txt"
134134

135135
# load the data
136136
Flux_lgr <- LoadLGR(file = example_data1,
@@ -158,7 +158,7 @@ This is how the “time\_cue” data frame looks like. Instead of having it
158158
created by the function `SelCue()`, one can also manually prepare such a
159159
file and load it into R as a data frame. But the column name (“End” or
160160
“Start”) and time format must be in line with the “time\_cue” here, or
161-
see example files Time & Ta\_1.csv and Time & Ta\_2.csv at
161+
see example files "Time\_&*Ta\_1.csv" and "Time*&\_Ta\_2.csv" at
162162
<https://github.com/junbinzhao/FluxCalR/tree/master/inst/extdata>).
163163

164164
``` r
@@ -213,7 +213,7 @@ head(Flux_output1)
213213
#> 3 3 2016-11-21 12:20:08 12:23:12 CO2 0.019 0.97 31.57 0.608
214214
#> 4 4 2016-11-21 12:25:19 12:28:23 CO2 0.017 0.95 32.11 0.543
215215
#> 5 5 2016-11-21 12:34:04 12:37:09 CO2 0.009 0.79 32.84 0.287
216-
#> 6 6 2016-11-21 12:39:21 12:42:25 CO2 0.050 0.99 33.20 1.591
216+
#> 6 6 2016-11-21 12:39:20 12:42:24 CO2 0.050 0.99 33.20 1.591
217217
```
218218

219219
For more details of the functions and examples, please check the
File renamed without changes.
File renamed without changes.

man/FluxCal.Rd

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/LoadLGR.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/SelCue.Rd

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)