Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


The 'get_ausplots' function in the 'ausplotsR' package extracts and compiles AusPlots data. Up to 8 different types of data can be obtained by setting the corresponding function arguments to TRUE/FALSE (i.e. 'site_info', 'structural_summaries', 'veg.vouchers', 'veg.PI', 'basal.wedge', 'soil_subsites', 'soil_bulk_density', and 'soil_character'). AusPlots data are extracted in to a list containing data frames, one data frame for data type requested. Other functions in the 'ausplotsR' can be used to pre-process the AusPlots raw data, preparing it for exploration, visualisation, and/or analysis (i.e. 'species_table', 'fractional_cover', 'growth_form_table', 'single_cover_value', and 'basal_area' functions). Each of these pre-processing functions returns data stored in a data frame.

Often we want to store the AusPlots data that we have extracted and/or created (e.g. via pre-processing and enriching the data frame with additional data) for future work. The advantages in doing so include:

  • Saving time: Loading AusPlots data from a file is typically much faster that extracting it live with the function 'get_ausplots' (and even faster that extracting it and pre-processing it).
  • Reproducibility: Extraction of AusPlots data is live, so it is possible that the data obtained between identical (i.e. with the same arguments) requests differ. Storing the data that we have used in our manipulations/visualisations/analyses in files allows reproducibility and seamless continuity of work.
  • Portability: The data frames saves into files can be open by other software (e.g. spreadsheets packages, statistical packages,….).

To store data contained in data frames we can used the functions 'write.table', 'write.csv', and 'write.csv2' in the 'utils' package (included in the R installation). See the functions help page for further details (i.e. ‘? write.table’).

  • 'write.table': Prints an R object, preferably a matrix or data frame, to a file or connection (“generalized files”, such as possibly compressed files, URLs, pipes, etc.). It allows great flexibility in the way the object it stored in the file via the function arguments.
  • 'write.csv': Wrapper for writing ‘CSV’ files in the format used in most countries (uses “.” for the decimal point and “,” as separator). Specifically, it sets the 'write.table' arguments to ‘sep=”,”’, ‘dec=”.”’, ‘qmethod = "double"’, and ‘col.names = NA’ if ‘row.names = TRUE’ (the default) and to ‘TRUE’ otherwise.
  • 'write.csv2': Wrapper for writing ‘CSV’ files in the format used in some Wester European locales (uses “,” for the decimal point and “.” as separator). Specifically, it sets the 'write.table' arguments to ‘sep=”.”’, ‘dec=”,”’, ‘qmethod = "double"’, and ‘col.names = NA’ if ‘row.names = TRUE’ (the default) and to ‘TRUE’ otherwise.

List are generic vectors containing other objects. They typically contain rugged data (i.e. data not in ‘rectangular’ form such as data contained in a matrix or data frame). This makes them unsuitable to be stored in a file using 'write.table' and its derivative functions. We can save lists (or other R objects) to a 'RData' file using the 'save' function in the 'base' package (included in the R installation). 'RData' files are specific to R and can store multiple R objects into a single file. The list can then be read back into R from the file by using the functions 'load' or 'attach' (or 'data' in some cases). See the functions help page for further details (i.e. ‘? save’, ‘? load’, and ‘? attach’).





EXAMPLES

Examples of how to save AusPlots data into files are presented below. Examples include saving data frames using the functions 'write.table' and 'write.csv', as well as saving list using the function 'save'.

Boxes with grey background contain code snippets, and boxes with white background containt code (text) outputs.



Preparation

.

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
# ====================
# Saving AusPlots data
# ====================

# Provide Path for Directory where data will be stored
file.path = "C:/Users/uqbblanc/Documents/TERN/CWDir_TutBasicAusPlots"

# Extract Date and Create a String to Represent it. To be used as Part of the File Name
today = toString(Sys.Date())
today

.

Div
stylebackground-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
## [1] "2019-06-25"

.

.

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
date.s = paste(substr(today,start=3,stop=4),substr(today,start=6,stop=7), 
               substr(today,start=9,stop=10),sep="") 
date.s

.

Div
stylebackground-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
## [1] "190625"

.

.

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
# Load 'auplotsR' library and Extract some AusPlots data
library(ausplotsR)
AP.data.l = get_ausplots( my.Plot_IDs=c("SATFLB0004", "QDAMGD0022", "NTASTU0002"), 
                          structural_summaries=TRUE, basal.wedge=TRUE)

.

Div
stylebackground-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
## User-supplied Plot_IDs located.

.

.

.

Example 1: Save an AusPlots retrived Data Frame, using 'write.table'

.

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
# Save an AusPlots retrived Data Frame, using 'write.table'
# =========================================================

# Visualise summary of the retrived Raw Basal Wedge data
summary(AP.data.l$veg.basal)

.

Div
stylebackground-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
##  site_location_name site_location_visit_id site_location_id
##  Length:95          Min.   :53705          Min.   :60122   
##  Class :character   1st Qu.:58429          1st Qu.:60122   
##  Mode  :character   Median :58429          Median :61138   
##                     Mean   :57395          Mean   :60635   
##                     3rd Qu.:58658          3rd Qu.:61138   
##                     Max.   :58658          Max.   :61138   
##    point_id         herbarium_determination veg_barcode       
##  Length:95          Length:95               Length:95         
##  Class :character   Class :character        Class :character  
##  Mode  :character   Mode  :character        Mode  :character  
##                                                               
##                                                               
##                                                               
##       hits        basal_area_factor   basal_area     site_unique       
##  Min.   : 1.000   Min.   :-1.0000   Min.   :-1.000   Length:95         
##  1st Qu.: 2.000   1st Qu.: 0.1000   1st Qu.: 0.300   Class :character  
##  Median : 5.000   Median : 0.1000   Median : 0.900   Mode  :character  
##  Mean   : 5.979   Mean   : 0.2495   Mean   : 1.885                     
##  3rd Qu.: 8.500   3rd Qu.: 0.5000   3rd Qu.: 2.875                     
##  Max.   :20.000   Max.   : 2.0000   Max.   :14.000

.

.

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
# Create Name of the file to be stored (including the date)
file.name = paste("AP_3Sites_BasalWedge",date.s,sep="_")
file.name

.

Div
stylebackground-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
## [1] "AP_3Sites_BasalWedge_190625"

.

.

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
# Add the "txt" extension
file.name = paste(file.name,"txt",sep=".")
file.name

.

Div
stylebackground-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
## [1] "AP_3Sites_BasalWedge_190625.txt"

.

.

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
# Save the Raw Basal Wedge data to a Text File with columns separated by tabs
write.table(AP.data.l$veg.basal, paste(file.path, file.name, sep="/"), sep="\t")

.

.

.

Example 2: Save an AusPlots derived Data Frame (generated for pre-processing), using 'write.csv'

.

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
# Save an AusPlots derived Data Frame (generated for pre-processing), using 'write.csv'
# =====================================================================================

# Compute Basal Area from Raw Basal Wedge data
AP.3Sites.BAperPlot = basal_area(AP.data.l$veg.basal, by.spp=FALSE, by.hits=FALSE)

# Visualise summary of the retrived Basal Area data
summary(AP.3Sites.BAperPlot)

.

Div
stylebackground-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
##  site_unique        basal_area_m2_ha
##  Length:3           Min.   :3.994   
##  Class :character   1st Qu.:5.947   
##  Mode  :character   Median :7.900   
##                     Mean   :6.631   
##                     3rd Qu.:7.950   
##                     Max.   :8.000

.

.

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
# Create Name of the file to be stored (including the date)
file.name = paste("AP_3Sites_BasalArea",date.s,sep="_")
file.name

.

Div
stylebackground-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
## [1] "AP_3Sites_BasalArea_190625"

.

.

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
# Add the "txt" extension
file.name = paste(file.name,"csv",sep=".")
file.name

.

Div
stylebackground-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
## [1] "AP_3Sites_BasalArea_190625.csv"

.

.

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
# Save the Basal Area data to a Text File with columns separated by tabs
write.csv(AP.3Sites.BAperPlot, paste(file.path, file.name, sep="/"))

.

.

.

Example 3: Save an AusPlots retrived list, using 'save'

.

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
# Save an AusPlots retrived list, using 'save'
# ============================================

# Visualise the Data Frames included in the retrived list containing AusPlots data
names(AP.data.l)

.

Div
stylebackground-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
## [1] "site.info"   "struct.summ" "veg.basal"   "veg.vouch"   "veg.PI"     
## [6] "citation

.

.

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
# Create Name of the file to be stored (including the date)
file.name = paste("AP_3Sites_SiteVegInfo",date.s,sep="_")
file.name

.

Div
stylebackground-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
## [1] "AP_3Sites_SiteVegInfo_190625"

.

.

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
# Add the "txt" extension
file.name = paste(file.name,"RData",sep=".")
file.name

.

Div
stylebackground-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
## [1] "AP_3Sites_SiteVegInfo_190625.RData"

.

.

Div
stylebackground-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem;
# Save the list containing all retrived AusPlots data
save(AP.data.l, file=paste(file.path, file.name, sep="/"))
#load(file=paste(file.path, file.name, sep="/"))

.

.

.