Skip to content

Basic examples #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
^renv$
^renv\.lock$
^.*\.Rproj$
^\.Rproj\.user$
^\.travis\.yml$
1 change: 1 addition & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source("renv/activate.R")
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ Thumbs.db
# RStudio files
.Rproj.user

renv/
_processedLockFile.lock
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
import(jaspBase)
export(AddOne)
export(ProcessData)
export(Parabola)
39 changes: 39 additions & 0 deletions R/examples.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
AddOne <- function(jaspResults, dataset, options) {
result <- as.character(options$my_number + 1) # options$my_number comes from the menu created by inst/qml/integer.qml

jaspResults[["result"]] <- createJaspHtml(text = result,
title = "This is your result:")

return()
}

ProcessData <- function(jaspResults, dataset, options) {
# Dataset access
# options$ts --maps to--> 't'
# dataset[, options$ts] --maps to--> dataset$t
result <- paste(dataset[, options$ts], collapse = "")
jaspResults[["result"]] <- createJaspHtml(text = result,
title = "This is your result:")

return()
}

Parabola <- function(jaspResults, dataset, options) {
# Analysis
f <- function(x) { options$a * x^2 } # Function to be plotted
p <- ggplot2::ggplot() + # Plotting command
ggplot2::xlim(-3, 3) +
ggplot2::ylim(0, 10) +
ggplot2::geom_function(fun = f)

# Aesthetics
parabolaPlot <- createJaspPlot(title = "Parabola",
width = 160,
height = 320)
parabolaPlot$dependOn(c("a")) # Refresh view whenever a changes

jaspResults[["parabolaPlot"]] <- parabolaPlot
parabolaPlot$plotObject <- p

return()
}
38 changes: 37 additions & 1 deletion inst/Description.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,46 @@ Description
{
name : "jaspModule"
title : qsTr("Jasp Module")
description : qsTr("This module offers analyses.")
description : qsTr("Examples for module builders")
version : "0.1"
author : "JASP Team"
maintainer : "JASP Team <[email protected]>"
website : "https://jasp-stats.org"
license : "GPL (>= 2)"
preloadData: true
requiresData: true


GroupTitle
{
title: qsTr("Basic functions")
}

Analysis
{
title: "Add one" // Title for window
menu: "Add one" // Title for ribbon
func: "AddOne" // Function to be called
qml: "integer.qml" // Design input window
}

Analysis
{
title: "Load data"
menu: "Load data"
func: "ProcessData"
qml: "data.qml"
}

GroupTitle
{
title: qsTr("Plotting")
}

Analysis
{
title: "Plot a parabola"
func: "Parabola"
qml: "parabola.qml"
}
}
40 changes: 40 additions & 0 deletions inst/qml/data.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Copyright (C) 2013-2018 University of Amsterdam
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public
// License along with this program. If not, see
// <http://www.gnu.org/licenses/>.
//
import QtQuick 2.8
import QtQuick.Layouts 1.3
import JASP.Controls 1.0
import JASP.Widgets 1.0
import JASP 1.0

Form
{

Text
{
text: "This example shows how to load a dataset and perform a simple operation on it"
}

VariablesForm
{
AvailableVariablesList { name: "allVariables" }
AssignedVariablesList { name: "ts"; label: qsTr("Times (t)"); singleVariable: true; allowedColumns: ["scale"] }
AssignedVariablesList { name: "xs"; label: qsTr("Horizontal positions (x)"); singleVariable: true; allowedColumns: ["scale"] }
AssignedVariablesList { name: "ys"; label: qsTr("Vertical positions (y)"); singleVariable: true; allowedColumns: ["scale"] }
}

}
44 changes: 44 additions & 0 deletions inst/qml/integer.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Copyright (C) 2013-2018 University of Amsterdam
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public
// License along with this program. If not, see
// <http://www.gnu.org/licenses/>.
//
import QtQuick 2.8
import QtQuick.Layouts 1.3
import JASP.Controls 1.0
import JASP.Widgets 1.0
import JASP 1.0

Form
{

Text
{
text: "This example shows how to manually introduce an input and perform a simple operation on it"
}

IntegerField
{
name: "my_number" // This will map to options$my_number in R
label: qsTr("Type a number") // qsTr allows for future translations

// We can add some extra control parameters
min: 1
defaultValue: 10
fieldWidth: 50
max: 1000
}

}
44 changes: 44 additions & 0 deletions inst/qml/parabola.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Copyright (C) 2013-2018 University of Amsterdam
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public
// License along with this program. If not, see
// <http://www.gnu.org/licenses/>.
//
import QtQuick 2.8
import QtQuick.Layouts 1.3
import JASP.Controls 1.0
import JASP.Widgets 1.0
import JASP 1.0

Form
{

Text
{
text: "This example shows how to plot a curve"
}

IntegerField
{
name: "a" // This will map to options$a in R
label: qsTr("Type a number") // qsTr allows for future translations

// We can add some extra control parameters
min: -10
defaultValue: 1
fieldWidth: 50
max: 10
}

}
Loading
Loading