Skip to content

Commit

Permalink
remove false dependence tsibble
Browse files Browse the repository at this point in the history
  • Loading branch information
antaldaniel committed Dec 20, 2024
1 parent e3aaee0 commit 607b3a6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
10 changes: 5 additions & 5 deletions R/dataset_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ dataset_df <- function(...,
}

if (is.null(dataset_bibentry)) {
Title="Untitled Dataset"
Creator=person("Author", "Unknown")
Title <- "Untitled Dataset"
Creator <- person("Author", "Unknown")
dataset_bibentry <- datacite(Title=Title, Creator=Creator, Subject=dataset_subject)
} else if(is.null(dataset_bibentry$subject)) {
#dataset_bibentry$subject <- dataset_subject$term
Expand Down Expand Up @@ -103,8 +103,8 @@ as_dataset_df <- function(df,
year <- substr(as.character(sys_time),1,4)

if (is.null(dots$dataset_bibentry)) {
Title="Untitled Dataset"
Creator=person("Author", "Unknown")
Title <- "Untitled Dataset"
Creator <- person("Author", "Unknown")

if(is.null(dataset_bibentry$year)) dataset_bibentry$year <- year
}
Expand Down Expand Up @@ -176,7 +176,7 @@ print.dataset_df <- function(x, ...) {
if (!is.null(author_person$given)) print_name <- paste0(print_name, author_person$given, ": ")
} else if (is.character(attr(x, "person"))) {
print_name <- paste0(attr(x, "person"), ": ")
} else { print_name = ""}
} else { print_name <- ""}

#if(!is.null(title)) {
# print_title <- title
Expand Down
7 changes: 3 additions & 4 deletions R/dataset_to_triples.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#' columns \code{s} for subject, \code{p} for predicate and \code{o} for
#' object.
#' @param x An R object that contains the data of the dataset (a data.frame or
#' inherited from [`data.frame`][base::data.frame()]), for example, [dataset_df()]
#' [tibble::tibble()], [tsibble::tsibble()], [data.table::data.table()].
#' inherited from [`data.frame`][base::data.frame()]), for example, [dataset_df()].
#' @param idcol The identifier column. If \code{idcol} is \code{NULL} it attempts to
#' use the \code{row.names(df)} as an \code{idcol}.
#' @return The long form version of the original dataset, retaining the attributes
Expand All @@ -18,9 +17,9 @@ dataset_to_triples <- function(x, idcol=NULL) {
is_dataset <- inherits(x, "dataset_df")

if (is_dataset) {
new_title = paste0(dataset_title(x), " [triple form]")
new_title < paste0(dataset_title(x), " [triple form]")
DataBibentry <- get_bibentry(x)
new_Subject <- subject(x)
new_Subject <- subject(x)
}

if (is.null(idcol)) {
Expand Down
2 changes: 1 addition & 1 deletion R/n_triple.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ prov_author <- function(author_person) {

} else if (is.character(attr(author_person, "person"))) {
print_name <- paste0(attr(author_person, "person"), ": ")
} else { print_name = ""}
} else { print_name <- ""}

if(!is.null(orcid)) {
triple_1 <- n_triple(orcid, "a", "http://www.w3.org/ns/prov#Agent")
Expand Down
3 changes: 1 addition & 2 deletions man/dataset_to_triples.Rd

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

8 changes: 6 additions & 2 deletions tests/testthat/test-var_namespace.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@

qid = defined(c("Q275912", "Q116196078"), namespace = "https://www.wikidata.org/wiki/")



test_that("var_namespace() works", {
qid <- defined(c("Q275912", "Q116196078"), namespace = "https://www.wikidata.org/wiki/")
expect_true(is.defined(qid))
expect_equal(var_namespace(qid),"https://www.wikidata.org/wiki/")
})


test_that("set_namespace_attribute() works", {
qid <- defined(c("Q275912", "Q116196078"), namespace = "https://www.wikidata.org/wiki/")
expect_equal(
get_namespace_attribute(set_namespace_attribute(qid, "https://www.wikiba.se/")), "https://www.wikiba.se/"
)
expect_error(set_namespace_attribute(qid, c("https://www.wikidata.org/wiki/", "https://www.wikiba.se/")))
})

var_namespace(qid) <- "https://www.wikibase.se/"

test_that("`var_namespace<-` works", {
var_namespace(qid) <- "https://www.wikibase.se/"
qid <- defined(c("Q275912", "Q116196078"), namespace = "https://www.wikidata.org/wiki/")
expect_equal(get_namespace_attribute(qid), "https://www.wikibase.se/")
expect_error(var_namespace(qid) <- c("https://www.wikidata.org/wiki/", "https://www.wikiba.se/"))
})
Expand Down
6 changes: 3 additions & 3 deletions vignettes/dataset_df.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ wikidata_countries <- c(
"http://www.wikidata.org/entity/Q3908", "http://www.wikidata.org/entity/Q1246")
# Retrieve their labels into a dataset called 'European countries':
wikidata_countries_df <- get_item(qid=wikidata_countries,
language="en",
wikidata_countries_df <- get_item(qid = wikidata_countries,
language ="en",
title = "European countries",
creator = person("Daniel", "Antal"))
Expand Down Expand Up @@ -138,7 +138,7 @@ knitr::kable(tdf)

```{r writettl, eval=FALSE}
example_file<- file.path(tempdir(), "example_ttl.ttl")
ttl_write(tdf=tdf, ttl_namespace = NULL, file_path = example_file)
ttl_write(tdf=tdf, ttl_namespace=NULL, file_path=example_file)
readLines(example_file)
```
Expand Down

0 comments on commit 607b3a6

Please sign in to comment.