Installing
#install the remotes package if you don't akready have it
install.packages("remotes")
#install the package
remotes::install_github("Kneerav/biomechanics")
Basic setup
To get going with the basic setup, you can just load your library.
library(biomechanics)
#> Warning: replacing previous import 'ggplot2::last_plot' by 'plotly::last_plot'
#> when loading 'biomechanics'
Please note that for full functionality, we also want the OpenSim api set up.
OpenSim api
Some functions depend on the OpenSim api (https://simtk.org/projects/opensim). To set this up, we first need to set up a Python environment.
Download and install either Anaconda or Miniconda from: https://www.anaconda.com/download. I prefer Miniconda, as it is a “lighter” version that takes up far less disk space than the full Anaoconda version (but also does not include common packages).
Next, create a new environment for the OpenSim conda package to be installed. It is best to use informative names, such as “opensim_scripting_45_311” indicating OpenSim v4.5 and python version 3.11.
-n "opensim_scripting_45_311" python=3.11 conda create
Alternatively (preferred), you can create the same environment by opening anaconda navigator and create a new environment called “opensim_scripting_45_311” with python version 3.11. This method is preferred because I have found that, in order for the OpenSim package install to work, we need to downgrade the OpenSSL package to 1.1.1w (which is most easily achieved in the anaconda navigator).
Open the conda prompt, then enter the code below to activate your new environment, and install the opensim package (latest version, which should be indicated here: https://anaconda.org/opensim-org/opensim).
conda activate opensim_scripting_45_311-org::opensim
conda install opensim
pythonimport opensim as osim
Then switch to the python interpreter to test your installation, by typing below.
pythonimport opensim as osim
If you have no errors, you are ready to roll. While you are here, you might as well install the additional python packages we might need as follows.
#to leave the python interpretor
exit() -c conda-forge btk #btk has numerous tools for working with c3d files
conda install #for signal processing
pip install scipy #for data management
pip install pandas #statistical parametric mapping pip install spm1d
Next, open R Studio and ensure that the reticulate
package is setup to work with our new environment. The easiest way I
have found to do this is as follows:
library(reticulate) #you should have installed this package already
Sys.setenv(RETICULATE_PYTHON = "C:/Users/nimaniar/.conda/envs/opensim_scripting_45_311") #change file path as needed
py_discover_config() #check to see if reading correct version of python, should be 3.11
osim = import("opensim")
Other r packages
There are plenty of other R packages worth installing. Here is a few basics:
install.packages(
c("tidyverse", #you probably know why
"readxl" #read excel files
"pracma", #maths stuff
"signal", #for signal processing
"caroline", #some useful utility functions
"fda", #functional data analysis
) )
Note that pracma
and signal
are already
dependencies for the biomechanics
package.
Other recommended installs
I’d also recommend the following installs to make life easier:
- OpenSim GUI - Graphical user interface for OpenSim (musculoskeletal modelling software) https://simtk.org/projects/opensim
- Notepad ++ - text editor which is very useful for opening .xml and other files https://notepad-plus-plus.org/
- Mokka - Motion capture data visualiser https://biomechanical-toolkit.github.io/mokka/