Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SchmidtPaul committed Jan 22, 2021
0 parents commit 15039c6
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
^.*\.Rproj$
^\.Rproj\.user$
^README\.Rmd$
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
22 changes: 22 additions & 0 deletions CitaviR.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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
PackageCheckArgs: --as-cran
PackageRoxygenize: rd,collate,namespace,vignette
11 changes: 11 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Package: CitaviR
Type: Package
Title: A set of tools for dealing with Citavi data
Version: 0.1.0
Author: Paul Schmidt <[email protected]>
Maintainer: Paul Schmidt <[email protected]>
Description: The reference management software Citavi <https://www.citavi.com/de> allows for exports to Excel. With a bit of effort (i.e. via customized Citavi Macros) it also allows for imports from Excel. CitaviR provides functionality for dealing with Citavi data.
License: GPL-3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.1
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Generated by roxygen2: do not edit by hand

export(read_Citavi_xlsx)
92 changes: 92 additions & 0 deletions R/read_Citavi_xlsx.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#' @title Importing Excel files created via Citavi Export
#'
#' @description Currently this only works for files that were generated while Citavi
#' was set to "English" or "German" so that column names are "Short title" or "Kurztitel" etc.
#'
#' @param path Path to the xls/xlsx file \href{https://www1.citavi.com/sub/manual6/en/index.html?exporting_to_excel.html}{created with Citavi via export to Excel}.
#' @param keepMarksCols If TRUE (default) it will keep and rename the first three
#' nameless columns of the imported excel file. These columns are automatically
#' created by the Citavi export and contain information about the attachment/paper-clip marker,
#' \href{https://www1.citavi.com/sub/manual6/en/index.html?using_labels.html}{the red flag marker and the blue circle marker}. If kept, the columns are renamed
#' \code{has_attachment}, \code{red_flag} and \code{blue_circle}.
#' If FALSE, these three columns are deleted.
#' @param useYearDerived If TRUE (default) the
#' \href{https://www1.citavi.com/sub/manual6/en/index.html?cse_using_special_components.html}{special column "Year derived"}
#' (DE: \href{https://www1.citavi.com/sub/manual6/de/index.html?cse_using_special_components.html}{"Jahr ermittelt"}) is renamed to "year" (DE:"Jahr") and thus replaces
#' the original basic column "year" (DE: "Jahr") which may have also been created
#' via the Citavi export.
#' @param setSuggestedColOrder If TRUE (default) columns a reordered in a suggested order.
#' @param ... Other arguments passed to the \code{\link{readxl::read_xlsx()}} function.
#'
#' @examples
#' \dontrun{
#' CitDat <- read_Citavi_xlsx("data/myCitaviExport.xlsx")
#' }
#'
#' @return A tibble containing the information of the xls/xlsx file \href{https://www1.citavi.com/sub/manual6/en/index.html?exporting_to_excel.html}{created with Citavi via export to Excel}.
#' @export

read_Citavi_xlsx <- function(path, keepMarksCols = TRUE, useYearDerived = TRUE, setSuggestedColOrder = TRUE, ...) {

# import ------------------------------------------------------------------
suppressMessages( # because usually the first three columns (=MarksCols) have no names so we get message that they are automatically renamed "...1", "...2" and "...3".
CitDat <- readxl::read_xlsx(path = path, ...)
)

# keepMarksCols: handle first 3 columns with marks ----------------
if ( all(names(CitDat)[1:3] == c("...1", "...2", "...3")) ) {

if (keepMarksCols) {

CitDat <- CitDat %>%
rename("has_attachment" = 1,
"red_flag" = 2,
"blue_circle" = 3)

} else {

CitDat <- CitDat %>%
select(-c("...1", "...2", "...3"))

}

}


# useYearDerived: use "Jahr ermittelt" instead of "Jahr" ---------
if (useYearDerived) {

year_key <-
c("Jahr" = "Jahr ermittelt",
"Year" = "Year derived")

if ( any(year_key %in% names(CitDat)) ) {

CitDat <- CitDat %>%
select(-matches(names(year_key)), everything()) %>% # delete original "year" if present
rename(year_key[year_key %in% names(CitDat)]) # rename "year derived" to "year"

}

}


# setSuggestedColOrder: order columns by default -----------------------------
if (setSuggestedColOrder) {

first_cols <- c("ID",
"Kurztitel", "Short title",
"Titel", "Title",
"Jahr", "Year")

last_cols <- c("has_attachment",
"red_flag",
"blue_circle")

CitDat <- CitDat %>%
relocate(any_of(first_cols[first_cols %in% names(CitDat)])) %>%
relocate(any_of(last_cols[last_cols %in% names(CitDat)]), .after = last_col())
}

CitDat
}
38 changes: 38 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# CitaviR

<!-- badges: start -->
<!-- badges: end -->

The reference management software Citavi <https://www.citavi.com/de> allows for exports to Excel. With a bit of effort (i.e. via customized Citavi Macros) it also allows for imports from Excel. CitaviR provides functionality for dealing with Citavi data.

## Installation

You can install the released version of CitaviR from [CRAN](https://CRAN.R-project.org) with:

``` r
install.packages("CitaviR")
```

## Example

This is a basic example which shows you how to solve a common problem:

```{r example}
library(CitaviR)
## basic example code
```
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# CitaviR

<!-- badges: start -->

<!-- badges: end -->

The reference management software Citavi <https://www.citavi.com/de>
allows for exports to Excel. With a bit of effort (i.e. via customized
Citavi Macros) it also allows for imports from Excel. CitaviR provides
functionality for dealing with Citavi data.

## Installation

You can install the released version of CitaviR from
[CRAN](https://CRAN.R-project.org) with:

``` r
install.packages("CitaviR")
```

## Example

This is a basic example which shows you how to solve a common problem:

``` r
library(CitaviR)
## basic example code
```
47 changes: 47 additions & 0 deletions man/read_Citavi_xlsx.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 15039c6

Please sign in to comment.