Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikkel Roald-Arbøl committed Mar 17, 2024
0 parents commit f0ff1d1
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
^renv$
^renv\.lock$
^.*\.Rproj$
^\.Rproj\.user$
1 change: 1 addition & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source("renv/activate.R")
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
renv
11 changes: 11 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Package: trackballr
Type: Package
Title: What the Package Does (Title Case)
Version: 0.1.0
Author: Who wrote it
Maintainer: The package maintainer <yourself@somewhere.net>
Description: More about what it does (maybe more than one line)
Use four spaces when indenting paragraphs within the Description.
License: What license is it under?
Encoding: UTF-8
LazyData: true
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exportPattern("^[[:alpha:]]+")
47 changes: 47 additions & 0 deletions R/augment_trackball.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#' Title
#'
#' @param data
#' @param x
#' @param y
#' @param sampling_rate
#' @param rollmean_k
#' @param mouse_dcpm
#'
#' @return
#' @export
#'
#' @examples
augment_trackball <- function(
data,
x,
y,
sampling_rate = 125,
rollmean_k = 30,
mouse_dcpm = 394
) {
data <- data %>%
mutate(row = row_number(),
time = row / sampling_rate,
x = y_Right,
x = zoo::rollmean(x, k = rollmean_k, fill = NA),
y = y_Left,
y = zoo::rollmean(y, k = rollmean_k, fill = NA),
cum_x = 0,
cum_y = 0) %>%
select(!c(1:4)) %>%
mutate(distance = sqrt(x^2 + y^2) / mouse_dpcm,
v_translation = distance * sampling_rate,
direction = atan2(y,x),
rotation = if_else(abs(x) > 1 & abs(y) > 1,
abs(lag(direction) - direction),
0),
rotation = if_else(rotation > pi, 2*pi - rotation, rotation),
v_rotation = rotation * sampling_rate) %>%
mutate(
x = replace_na(x, 0),
y = replace_na(y, 0))
# filter(distance < 1000) # Filters away trials covering less than 1000 pixels
data$cum_x <- cumsum(data$x)
data$cum_y <- cumsum(data$y)
return(data)
}
11 changes: 11 additions & 0 deletions R/mode.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#' Title
#'
#' @param x A vector of numbers
#'
#' @return
#' @export
#'
#' @examples
mode <- function(x){
which.max(tabulate(x))
}
15 changes: 15 additions & 0 deletions R/read_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#' Title
#'
#' @param data
#' @param sensor_names
#'
#' @return
#' @export
#'
#' @examples
read_trackball_from_rdata <- function(
data,
sensor_names = c("Left", "Right")
){

}
12 changes: 12 additions & 0 deletions man/hello.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
\name{hello}
\alias{hello}
\title{Hello, World!}
\usage{
hello()
}
\description{
Prints 'Hello, world!'.
}
\examples{
hello()
}
23 changes: 23 additions & 0 deletions renv.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"R": {
"Version": "4.3.2",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://packagemanager.posit.co/cran/latest"
}
]
},
"Packages": {
"renv": {
"Package": "renv",
"Version": "1.0.3",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"utils"
],
"Hash": "41b847654f567341725473431dd0d5ab"
}
}
}
20 changes: 20 additions & 0 deletions trackballr.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source

0 comments on commit f0ff1d1

Please sign in to comment.