| 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 |
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
nettskjema_tsd_apply_edits( input_file, edits_file, output_file = NULL, verbose = NULL )nettskjema_tsd_apply_edits( input_file, edits_file, output_file = NULL, verbose = NULL )
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. |
data.frame with edited nettskjema data
Apply edits to all nettskjema data
nettskjema_tsd_apply_edits_all( input_dir = NULL, pattern = NULL, suffix = "-ed", project = NULL, output_dir = NULL )nettskjema_tsd_apply_edits_all( input_dir = NULL, pattern = NULL, suffix = "-ed", project = NULL, output_dir = NULL )
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. |
data frame with edits applied
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.
nettskjema_tsd_csv2data(input_dir, output_file = NULL)nettskjema_tsd_csv2data(input_dir, output_file = NULL)
input_dir |
character. Path to input directory. |
output_file |
character. Path to output file. |
data.frame with all data
## 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)## 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)
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.
nettskjema_tsd_decrypt_all_forms( path = NULL, project = NULL, output_dir = NULL, rerun_all = FALSE, verbose = NULL, ... )nettskjema_tsd_decrypt_all_forms( path = NULL, project = NULL, output_dir = NULL, rerun_all = FALSE, verbose = NULL, ... )
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 |
success list
Decrypt nettskjema file
nettskjema_tsd_decrypt_file( path, output_path = gsub("\\.asc", "", path), pretty = TRUE )nettskjema_tsd_decrypt_file( path, output_path = gsub("\\.asc", "", path), pretty = TRUE )
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. |
raw decrypted file content as text
Decrypt all files associated with a form
nettskjema_tsd_decrypt_form( path, rerun_all = FALSE, output_dir = NULL, verbose = NULL, ... )nettskjema_tsd_decrypt_form( path, rerun_all = FALSE, output_dir = NULL, verbose = NULL, ... )
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 |
nothing. Writes decrypted files to a folder.
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'.
nettskjema_tsd_import_key(path = NULL, verbose = NULL)nettskjema_tsd_import_key(path = NULL, verbose = NULL)
path |
full path to the key-file. |
verbose |
logical. Should the function output status messages. Default is TRUE. |
Nothing. Imports the key to the session
## 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)## 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)
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.
nettskjema_tsd_json2data(input_dir, output_file = NULL)nettskjema_tsd_json2data(input_dir, output_file = NULL)
input_dir |
character. Path to input directory. |
output_file |
character. Path to output file. |
data.frame with all data
## 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)## 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)
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.
nettskjema_tsd_keyfile( path = Sys.getenv("nettskjema.tsd.keyfile"), project = NULL, verbose = NULL )nettskjema_tsd_keyfile( path = Sys.getenv("nettskjema.tsd.keyfile"), project = NULL, verbose = NULL )
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. |
character with the full verified path
## Not run: nettskjema_tsd_keyfile() nettskjema_tsd_keyfile(path = "/my/keyfile/path/secret.asc") ## End(Not run)## Not run: nettskjema_tsd_keyfile() nettskjema_tsd_keyfile(path = "/my/keyfile/path/secret.asc") ## End(Not run)
Decrypt all forms associated with a project
nettskjema_tsd_organise_all_forms(rerun_all = FALSE, ...)nettskjema_tsd_organise_all_forms(rerun_all = FALSE, ...)
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 |
nothing. Writes decrypted files to a folder.
Decrypt all files associated with a form
nettskjema_tsd_organise_form( formid, project = NULL, output_dir = NULL, rerun_all = FALSE, verbose = NULL, pretty = TRUE )nettskjema_tsd_organise_form( formid, project = NULL, output_dir = NULL, rerun_all = FALSE, verbose = NULL, pretty = TRUE )
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. |
logical. If new entries were decrypted or not.
Find the path for encrypted Nettskjema data
nettskjema_tsd_submission_path(project = NULL)nettskjema_tsd_submission_path(project = NULL)
project |
current TSD project. Will automatically auto-detect project. |
single character path
Utility function to read in nettskjema data. forced all columns to character to not loose leading zero.
read_nettskjema_tsd(path)read_nettskjema_tsd(path)
path |
string path to a nettskjema file |
a dataframe with nettskjema data
## Not run: read_nettskjema_tsd("/tsd/pxx/nettskjema/form.csv") ## End(Not run)## Not run: read_nettskjema_tsd("/tsd/pxx/nettskjema/form.csv") ## End(Not run)