Developing R Packages
Jasmin Ludolf
Content Developer
time_converter <- function(time, unit_from, unit_to) {
# Define conversion factors for different time units
conversion_factors <- c(hour = 3600, minute = 60, second = 1)
# Convert time to seconds
in_seconds <- time * conversion_factors[unit_from]
# Convert time from seconds to the desired unit
return(unname(in_seconds / conversion_factors[unit_to]))
}
time_converter(24, "hours", "seconds")
86400
dump("time_converter", file = "R/time_converter.R")
library(devtools)
load_all()
- Loading unitConverter
time_converter <-
function(time, unit_from, unit_to) {
if ( (unit_from == "hours" && unit_to == "minutes") ||
(unit_from == "minutes" && unit_to == "seconds") ) {
return(time * 60)
} else if ( (unit_from == "minutes" && unit_to == "hours") ||
(unit_from == "seconds" && unit_to == "minutes") ) {
return(time / 60)
} else if (unit_from == "hours" && unit_to == "seconds") {
return(time * 3600)
} else if (unit_from == "seconds" && unit_to == "hours") {
return(time / 3600)
} else {
return(time) # No conversion needed
}
load_all()
- Loading unitConverter
Error in `load_all()`:
! Failed to load R/time_converter.R
Caused by error in `parse()`:
! ~/unitConverter/R/time_converter.R:17:0: unexpected end of input
15:
16: }
^
Run `rlang::last_trace()` to see where the error occurred.
load_all()
install()
load_all()
check()
Sample last line of output from check()
0 errors | 2 warnings X | 1 note X
Ideal state
0 errors | 0 warnings | 0 notes
Developing R Packages