# MacroecoDesktop for R users¶

Users who primarily work in R can access the functionality of macroeco through the command line MacroecoDesktop interface.

First, install a working copy of MacroecoDesktop by following the installation instructions in Installation. Windows and Linux users will need to install a Python environment and the macroeco package, while Mac users can instead install the standalone MacroecoDesktop program. Follow the First steps: MacroecoDesktop tutorial to create the new_parameters.txt file and ensure that your copy of MacroecoDesktop is working properly.

For all platforms and installation options, the basic idea will be to call MacroecoDesktop from an R script using the command line interface, wait for the analysis to complete, and then read in any output tables saved by MacroecoDesktop that will be used for further analysis.

As an example, the script below completes the following steps:

• Writes a new_parameters.txt file describing a desired MacroecoDesktop analysis

• Uses the system command within R to execute the MacroecoDesktop analysis specified in new_parameters.txt

• Reads in the resulting data tables

• Plots gridded distance decay data with a best fit power law curve

• Prints out the R2 value for the power law fit to the data:

param_dir <- "/Users/jkitzes/Desktop/"
param_file <- "new_parameters.txt"

cat("
[DistanceDecay]

analysis = comm_grid

cols = spp_col: spp; count_col: count; y_col: row; x_col: column
divs = 4,4
models = power_law
",file=paste(param_dir,param_file,sep=""), sep="\n")

system(paste("/Users/jkitzes/anaconda/bin/python -c  \"import macroeco; macroeco.desktop(\'", param_dir, param_file, "\')\"", sep=""))

plot(data_models$x, data_models$empirical)
lines(data_models$x, data_models$power_law)