Package 'nettskjema.tsd'

Title: Decrypt and Organise Nettskjema Data Within TSD
Description: Working with Nettskjema (<https://nettskjema.no/>) data inside TSD can be challenging. This package aims to aid users in managing their incoming Nettskjema data by decrypting the data and storing the nettskjema data and meta-data in convenient and standardised ways. This package functionality currently only works on the Linux VMs of TSD, and for version 1 of the nettskjema data delivery to TSD.
Authors: Athanasia Mo Mowinckel [aut, cre] (ORCID: <https://orcid.org/0000-0002-5756-0223>)
Maintainer: Athanasia Mo Mowinckel <[email protected]>
License: MIT + file LICENSE
Version: 0.0.1
Built: 2026-05-30 09:09:57 UTC
Source: https://github.com/LCBC-UiO/nettskjema.tsd

Help Index


Apply edits to nettskjema data

Description

Nettskjema data can at times contain errors that require manual editing. Editing raw files directly is not recommended practice, as logging these changes often is not maintained over time. Applying edits to nettskjema data through a more transparent manner means keeping raw data in its original state, while also keeping track of the changes needed. This function needs a json formatted file to apply edits to either raw csv or json data from nettskjema. TODO: make vignette with instructions on edit.json TODO: make functions to initiate/add edits

Usage

nettskjema_tsd_apply_edits(
  input_file,
  edits_file,
  output_file = NULL,
  verbose = NULL
)

Arguments

input_file

string. file path to the raw nettskjema file, that contains all answers for a form, you want to apply edits to.

edits_file

string. file path to the json with the edits that should be applied

output_file

character. Path to output file.

verbose

logical. Should the function output status messages. Default is TRUE.

Value

data.frame with edited nettskjema data


Apply edits to all nettskjema data

Description

Apply edits to all nettskjema data

Usage

nettskjema_tsd_apply_edits_all(
  input_dir = NULL,
  pattern = NULL,
  suffix = "-ed",
  project = NULL,
  output_dir = NULL
)

Arguments

input_dir

directory path where the input files are

pattern

regex pattern to match files with

suffix

character. String to be added at the end of files with edits applied.

project

current TSD project. Will automatically auto-detect project.

output_dir

character. Path to output directory.

Value

data frame with edits applied


Combine csv's from Nettskjema (on TSD)

Description

The submissions received on TSD arrive as both csv and jsons. Combining all these files produce the entire data from a form. This function combines all the csv within TSD to create a unified data.frame. If output_file is provided, will also write the the data for a file.

Usage

nettskjema_tsd_csv2data(input_dir, output_file = NULL)

Arguments

input_dir

character. Path to input directory.

output_file

character. Path to output file.

Value

data.frame with all data

Examples

## Not run: 
nettskjema_tsd_csv2data("/durable/nettskjema-submissions/cleaned/80902")

nettskjema_tsd_csv2data("/durable/nettskjema-submissions/cleaned/80902",
    output_file = "/durable/nettskjema-submissions/cleaned/80902/data.csv")

## End(Not run)

Decrypt all Nettskjema forms

Description

Given that all forms are placed in the same basic folder structures (as they are delivered to TSD), this function will detect all forms in the path provided and decrypt all the forms available.

Usage

nettskjema_tsd_decrypt_all_forms(
  path = NULL,
  project = NULL,
  output_dir = NULL,
  rerun_all = FALSE,
  verbose = NULL,
  ...
)

Arguments

path

path to the folder containing all the forms

project

current TSD project. Will automatically auto-detect project.

output_dir

character. Path to output directory.

rerun_all

logical. Should the process be run on all files, even those previously run. Default is FALSE.

verbose

logical. Should the function output status messages. Default is TRUE.

...

other arguments to mapply

Value

success list


Decrypt nettskjema file

Description

Decrypt nettskjema file

Usage

nettskjema_tsd_decrypt_file(
  path,
  output_path = gsub("\\.asc", "", path),
  pretty = TRUE
)

Arguments

path

path to file to decrypt

output_path

path to output decrypted file to. NULL will return file content to R.

pretty

logical. Should the submission json's be prettified. Default is TRUE.

Value

raw decrypted file content as text


Decrypt all files associated with a form

Description

Decrypt all files associated with a form

Usage

nettskjema_tsd_decrypt_form(
  path,
  rerun_all = FALSE,
  output_dir = NULL,
  verbose = NULL,
  ...
)

Arguments

path

path to the folder with encrypted data

rerun_all

logical. Should the process be run on all files, even those previously run. Default is FALSE.

output_dir

character. Path to output directory.

verbose

logical. Should the function output status messages. Default is TRUE.

...

other arguments to nettskjema_tsd_decrypt_file

Value

nothing. Writes decrypted files to a folder.


Import GPG key

Description

As a security measure, all submissions to Nettskjema data in to TSD are encrypted. These encrypted files need to be decrypted before they can be sorted and prepared for use in R (or other programs). To decrypt the data, R needs to have access to the secret key that will verify that the decryption is ok to carry out. This function will import the necessary key for the decryption to take place. If the key-file for the decryption is not automatically detected, contact IT to learn where your key has been stored. Any R-script you will run can then specify the location of the key-file either directly in the call to this function, or as an R-environment variable 'nettskjema.tsd.keyfile=/full/path/to/keyfile'.

Usage

nettskjema_tsd_import_key(path = NULL, verbose = NULL)

Arguments

path

full path to the key-file.

verbose

logical. Should the function output status messages. Default is TRUE.

Value

Nothing. Imports the key to the session

Examples

## Not run: 
nettskjema_tsd_import_key()
nettskjema_tsd_import_key(verbose = FALSE)
nettskjema_tsd_import_key(path = "/my/keyfile/path/secret.asc")

## End(Not run)

Combine csv's from Nettskjema (on TSD)

Description

The submissions received on TSD arrive as both csv and jsons. Combining all these files produce the entire data from a form. This function combines all the jsons within TSD to create a unified data.frame. If output_file is provided, will also write the the data for a file.

Usage

nettskjema_tsd_json2data(input_dir, output_file = NULL)

Arguments

input_dir

character. Path to input directory.

output_file

character. Path to output file.

Value

data.frame with all data

Examples

## Not run: 
nettskjema_tsd_json2data("/durable/nettskjema-submissions/cleaned/80902")

nettskjema_tsd_json2data("/durable/nettskjema-submissions/cleaned/80902",
    output_file = "/durable/nettskjema-submissions/cleaned/80902/data.csv")

## End(Not run)

Nettskjema TSD keyfile location

Description

As a security measure, all submissions to Nettskjema data in to TSD are encrypted. These encrypted files need to be decrypted before they can be sorted and prepared for use in R (or other programs). To decrypt the data, R needs to have access to the secret key that will verify that the decryption is ok to carry out. This function can verify the existence of a key-file given a specified location, or attempt to auto-detect a key-file.

Usage

nettskjema_tsd_keyfile(
  path = Sys.getenv("nettskjema.tsd.keyfile"),
  project = NULL,
  verbose = NULL
)

Arguments

path

full path to the key-file

project

current TSD project. Will automatically auto-detect project.

verbose

logical. Should the function output status messages. Default is TRUE.

Value

character with the full verified path

Examples

## Not run: 
nettskjema_tsd_keyfile()
nettskjema_tsd_keyfile(path = "/my/keyfile/path/secret.asc")

## End(Not run)

Decrypt all forms associated with a project

Description

Decrypt all forms associated with a project

Usage

nettskjema_tsd_organise_all_forms(rerun_all = FALSE, ...)

Arguments

rerun_all

logical. Should the process be run on all files, even those previously run. Default is FALSE.

...

arguments to pass to nettskjema_tsd_organise_form

Value

nothing. Writes decrypted files to a folder.


Decrypt all files associated with a form

Description

Decrypt all files associated with a form

Usage

nettskjema_tsd_organise_form(
  formid,
  project = NULL,
  output_dir = NULL,
  rerun_all = FALSE,
  verbose = NULL,
  pretty = TRUE
)

Arguments

formid

integer or character. Form number to process

project

current TSD project. Will automatically auto-detect project.

output_dir

directory to output data

rerun_all

logical. Should the process be run on all files, even those previously run. Default is FALSE.

verbose

logical. Should the function output status messages. Default is TRUE.

pretty

logical. Should the submission json's be prettified. Default is TRUE.

Value

logical. If new entries were decrypted or not.


Find the path for encrypted Nettskjema data

Description

Find the path for encrypted Nettskjema data

Usage

nettskjema_tsd_submission_path(project = NULL)

Arguments

project

current TSD project. Will automatically auto-detect project.

Value

single character path


Read nettskjema data

Description

Utility function to read in nettskjema data. forced all columns to character to not loose leading zero.

Usage

read_nettskjema_tsd(path)

Arguments

path

string path to a nettskjema file

Value

a dataframe with nettskjema data

Examples

## Not run: 
read_nettskjema_tsd("/tsd/pxx/nettskjema/form.csv")

## End(Not run)