knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
#install the remotes package if you don't akready have it install.packages("remotes") #install the package remotes::install_github("Kneerav/biomechanics")
To get going with the basic setup, you can just load your library.
library(biomechanics)
Please note that for full functionality, we also want the OpenSim api set up.
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.
```{python create, eval=F, echo=T, python.reticulate = FALSE} conda create -n "opensim_scripting_45_311" python=3.11
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>). ```{python installpy, eval=F, echo=T, python.reticulate = FALSE} conda activate opensim_scripting_45_311 conda install opensim-org::opensim python import opensim as osim
Then switch to the python interpreter to test your installation, by typing below.
```{python import, eval=F, echo=T, python.reticulate = FALSE} python import 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. ```{python other_py, eval=F, echo=T, python.reticulate = FALSE} exit() #to leave the python interpretor conda install -c conda-forge btk #btk has numerous tools for working with c3d files pip install scipy #for signal processing pip install pandas #for data management pip install spm1d #statistical parametric mapping
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")
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.
I'd also recommend the following installs to make life easier:
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.