Skip to content
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

BUG: Dropping optional fields may give an error on unknown path(s) #17

Open
HenrikBengtsson opened this issue Aug 2, 2018 · 2 comments

Comments

@HenrikBengtsson
Copy link
Owner

HenrikBengtsson commented Aug 2, 2018

It's not possible to drop optional fields. The following is an example with an optional key and value pair:

> dirdf::dirdf_parse(c("foo,tag=100.rds", "bar.rds"), template = "name,key?=value?.ext")
  name  key value ext        pathname
1  foo  tag   100 rds foo,tag=100.rds
2  bar <NA>  <NA> rds         bar.rds

However, it is not safe to drop an optional field because it may result in "unexpected paths". For example, if we try to drop the key fields, we get:

> dirdf::dirdf_parse(c("foo,tag=100.rds", "bar.rds"), template = "name,~key?~=value?.ext")
Error in dirdf::dirdf_parse(c("foo,tag=100.rds", "bar.rds"), template = "name,~key?~=value?.ext") : 
  Unexpected path(s) found:
bar.rds

Ideally we would get:

> dirdf::dirdf_parse(c("foo,tag=100.rds", "bar.rds"), template = "name,~key~?=value?.ext")
  name value ext        pathname
1  foo   100 rds foo,tag=100.rds
2  bar  <NA> rds         bar.rds
@HenrikBengtsson
Copy link
Owner Author

Clarification, without non-matching files, it works, e.g.

> dirdf::dirdf_parse("foo,tag=100.rds", template = "name,~key?~=value?.ext")
  name value ext        pathname
1  foo   100 rds foo,tag=100.rds

BTW, this format doesn't give an error but the wrong result:

> dirdf::dirdf_parse("foo,tag=100.rds", template = "name,~key~?=value?.ext")
  name value ext        pathname
1  foo  <NA> rds foo,tag=100.rds

@HenrikBengtsson
Copy link
Owner Author

Now ~key~? gives an error:

> dirdf::dirdf_parse("foo,tag=100.rds", template = "name,~key~?=value?.ext")
Error in templateToRegex(template) : 
  Invalid template. ~name~? is invalid whereas ~name?~ is valid:name,~key~?=value?.ext

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant